0
我對javascript中的評估順序感到困惑。對於恩,這是我寫JavaScript中的評估順序
this.getTabUrl=function()
{
this.logToConsole("1"+"getTabUrl is called");
var myUrl
chrome.tabs.getSelected(null, function(tab)
{
myUrl = tab.url;
console.log("2"+tab.url);
console.log("3"+myUrl);
//this.parent.logToConsole(tabUrl);
});
this.tabUrl=myUrl;
this.logToConsole("3.1"+myUrl);
this.logToConsole("4"+this.tabUrl);
return myUrl;
}
當我調用該函數的代碼,這是輸出我得到
> 1getTabUrl is called
> 3.1undefined
> 4undefined
> 2undefined
怎麼來的3.1和4 2
謝謝。這help.s我只是想返回Url,getTabUrl函數,你能告訴我如何去做 – 2011-06-02 21:59:04
看到我的最後兩句話。 – ThiefMaster 2011-06-02 22:00:19
你能指點我一個例子嗎?我是新來的JavaScript – 2011-06-02 22:07:06