Bind this context in object - Javascript Object

Javascript examples for Object:Object Context

Description

Bind this context in 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  ww.j  ava  2  s.c o m*/
var testObj = {
    name: "my object",
    logName: function() {
        console.log(this.name);
        var logNameAgain = function() {
            console.log(this.name);
        }.bind(this);
        logNameAgain();
    }
};
testObj.logName();
    }

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

Related Tutorials