defining getters/setters in an object literal with a self-invoking function javascript -
It is possible to use a self-encoding function when defining an object so that the function has access to a private variable ,
obj = {value: (function () {var personal; return function () {back true;}} ())}; But is it possible to do the same thing with a waiter / setter in the object?
obj = {get value () {return value; }, Set the value (v) {value = v; }};
Not really you have made IIF for obj Can: obj = function () {var privateatething = 'hithere'; Return {Get value} (back privatization)}, set the value (v) {privatething = v; }}; } (); obj.value; // = & gt; 'Hello'; obj.value = 'Good morning to you too'; obj.value; // = & gt; 'You too good morning'
Comments
Post a Comment