HOW TO SETTER GETTER IN JAVA SCRIPT


HOW TO SET SETTER GETTER IN JAVA SCRIPT

function SonyDaman() {
  var myVal = null;
  var myData = [];
Object.defineProperty(this, 'myVal', {
    get: function() {
      return myData ;
    },
    set: function(value) {
      myVal = value;
      myData .push({ val: myVal });
    }
  });
}

var sd= new SonyDaman();
sd.myVal = 11;  // setter
sd.myVal = 13; // setter
sd.myVal; // 'getter!'

0 Comments