javascript - this keyword in a class method -


var mc = function(map){     var init = function(imap){         alert("init " + + " with");     }     init(map); }; var m = new mc({}); 

why getting value of [object window]? window object??

yes! because init variable of mc, share scope (which global scope, window object).

however. if changed following:

var mc = function(map){     this.init = function(imap){         alert("init " + + " with");     }     this.init(map); }; var m = new mc({}); 

then this inside init reference instance.


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -