我正在尝试编写一个浏览器插件。但是我的JS有点生锈。有人可以解释为什么我不能调用“ presentTheAnswer”方法吗?我收到此错误:
Uncaught ReferenceError: presentTheAnswer is not defined
at getData (<anonymous>:4:13)
at <anonymous>:5:11
代码在这里
document.getElementById("mightyButton").addEventListener('click', () => {
console.log("Popup DOM fully loaded and parsed");
function getData() {
var data = 42;
presentTheAnswer(data);
}
function presentTheAnswer(data){
//do something
}
//We have permission to access the activeTab, so we can call chrome.tabs.executeScript:
chrome.tabs.executeScript({
code: '(' + getData + ')();' //argument here is a string but function.toString() returns function's code
}, null);
});
如果顺序很重要,我已经尝试过了(例如在C中?)。但这并没有改变