Use this or object name to reference the parent object - Javascript Object

Javascript examples for Object:Private Member

Description

Use this or object name to reference the parent 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() {//from www . j a  v a2  s .c  o m
    var Obj = {
        foo : 'value',
        bar : function() { console.log(this.foo); },
        //bar : function() { return Obj.foo; }
    }
    Obj.bar();
    });

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

Related Tutorials