javascript - pass constructor object into self invoke function -
#1 //pass obj self invoke, works fine var foo = { a: 1 }; (function(o){ console.log(o.a); })(foo); #2 //this not working var foo = function(){ this.a = 1; }; (function(o){ console.log(o); })(foo);
i'm new in javascript, try pass object self invoke
my problem when try pass constructor obj, not working
anyone know why?
in order #2
work have correct follows;
var foo = (function(){ return this.a = 1; })(); (function(o){ console.log(o); })(foo);
Comments
Post a Comment