Hi,
Somehow I am having troubles understanding the scoping problem in the code below. I assumed an anonymous function would capture dynamically the scoping of its surrounding vars. From what I read on Javascript this should work.
As I am not a Javascript expert, in fact, its my first use of the language, I might as well have applied the concept wrong.
In the example below I would expect isWincognito and isTabcognito to point to the values determined by the callback functions.
Any help is greatly appreciated!
Thanks!Code:function isIncognitoMode() { // it seems that the scope of is(Win|Tab)cognito // not captured properly when accessed in anonymous function var isWincognito = false; var isTabcognito = false; // get win & tag incognito states chrome.windows.getCurrent(function(win) { isWincognito = win.incognito; }); chrome.tabs.getCurrent(function(tab) { isTabcognito = tab.incognito; }); // somehow is(Win|Tab)cognito do not point to the values // determined by the callback functions. //console.log(this.isWincognito); return isTabcognito || isWincognito; }
Fabio


LinkBack URL
About LinkBacks



Reply With Quote
