chrome蓝牙API上的意外标识符错误

Unexpected identifier error on the chrome bluetooth API

本文关键字:意外 标识符 错误 蓝牙 API chrome      更新时间:2023-09-26

我目前正在使用蓝牙API编程谷歌chrome扩展(我的chrome版本是chrome-dev,因为蓝牙API仅在chrome-dev上)。我在这个脚本(notify.js)的第一行得到一个"意外的标识符错误"

chrome.bluetooth.getAdapterState( function(AdapterState result) {
    if (result.powered == false || result.available == false ) {
        alert("no bluetooth!!!");
    } else {
        alert("bluetooth!!!");
    }
});

有人知道如何解决这个问题吗?由于

  • Chrome使用Javascript作为其应用程序API。Javascript是一种动态类型语言。因此,您不需要指定对象的类型(当您向函数发送参数时也不需要)。

所以只要删除"AdapterState"部分,"Unexpected identifier error"就不会再出现了。

chrome.bluetooth.getAdapterState( function(result) {
  if (result.powered == false || result.available == false ) {
    alert("no bluetooth!!!");
  } else {
    alert("bluetooth!!!");
  }
});