javascript - How to pass a property by reference -
is there way pass object property function reference instead of value?
es5 properties can have getters , setters. how pass variable uses getters , setters instead of result of getter?
right have pass reference whole object, not single property want.
is there way pass object property function reference instead of value?
no. in fact doesn't make lot of sense "pass object property", notion of "property" doesn't exist without entity property of.
if matter of encapsulation , not wanting leak full control, can creative. e.g.,
var obj = { sensitive: 'do not share me!', public: 'hi there', setpublic: function(val) { this.public = val; } }; function somefunction(setter) { setter('new value'); } somefunction(obj.setpublic.bind(obj));
Comments
Post a Comment