Objects with properties that are functions details about 'this' - Javascript Object

Javascript examples for Object:Object Property

Description

Objects with properties that are functions details about 'this'

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   ww w .  ja  v a 2 s . com
var foo = {
  p1: function(){
    return this.p2;
  },
  p2: function(){
    console.log('i am foo.p2');
  }
};
document.write("Foo.p1: <br /><pre>" + foo.p1() + "</pre>");
    });

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

Related Tutorials