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

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

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -