Renaming the 'this' keyword in object constructor - Javascript Object

Javascript examples for Object:this

Description

Renaming the 'this' keyword in object constructor

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  a2  s .c  o m*/
var obj1 = { a: 1 }
,   obj2 = obj1
,   obj3 = obj2;
obj3.original = obj1;
obj2.a = 51;

console.log(obj3.original.a);

function User(name) {
    this.name = name;
}
var a = new User('a')
,   b = a
,   c = b;

c.original = a;
b.name = 'b';

console.log(c.original.name);
    });

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

Related Tutorials