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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -