How to access outer object in javascript objects -
assume code like. want access , j in function somefunc. how achieved?
var myobj = function(){ object.defineproperty(this, 'j'){ get: function() { return 1;} }; } myobj.prototype = object.create(null); myobj.prototype={ constructor : myobj, : 1, somefunc : function(){ console.log(i + j); } }
they can accessed through this.i , this.j
var myobj = function(){ object.defineproperty(this, 'j'){ get: function() { return 1;} }; } myobj.prototype = object.create(null); myobj.prototype={ constructor : myobj, : 1, somefunc : function(){ console.log(this.i + this.j); } }
Comments
Post a Comment