Implement getter and setter on object - Javascript Object

Javascript examples for Object:Object Method

Description

Implement getter and setter on object

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/* w w w.jav a  2s.  c om*/
var Application = function(){
    this.local = {};
};
Application.prototype.Value = function(){
    if (arguments.length) {
        this.local.result = arguments[0];
    }else{
        return this.local.result;
    }
};
var app = new Application();
app.Value(6);
console.log(app.Value());
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials