嵌套函数-未定义变量

时间:2018-08-29 20:26:28

标签: javascript

  

错误:此处未定义“ chromeWindow.state”

你能给我正确的方向吗?

chrome.runtime.onMessage.addListener(function(message,sender,sendResponse) 
{
  chrome.windows.get(sender.tab.windowId, function(chromeWindow) {
    // chromeWindow is DEFINED HERE
    console.log('sending to contentscript :', chromeWindow.state);
  });
  // chromeWindow.state is UNDEFINED
  sendResponse(**chromeWindow.state**);
});

1 个答案:

答案 0 :(得分:0)

chrome.runtime.onMessage.addListener(function(message,sender,sendResponse) 
{
  chrome.windows.get(sender.tab.windowId, function(chromeWindow) {
      sendResponse(chromeWindow.state);
  });
});