Extend the Scope of This - Javascript Object

Javascript examples for Object:this

Description

Extend the Scope of 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(){//w  ww .  ja  v a 2s  .c om
var myObj = {
   test: "Hello",
   test2: " World",
   run: {
      all: function() {
         return this.test + this.test2;
      },
      part: function() {
         return this.test2;
      }
   }
};
console.log(myObj.run.all.bind(myObj)());
console.log(myObj.run.part.bind(myObj)());
    }

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

Related Tutorials