kucukkanat
12/28/2015 - 9:41 PM

Javascript variable watcher

Javascript variable watcher

var obj = {};
 
Object.defineProperty(obj, "name", {
    get : function(){ return this._name;},
    set: function(val){  this._name = val;}
});
 
obj.name;
//undefined
 
obj.name = "name";
obj.name;
//name