Object prototype from instance - Javascript Object

Javascript examples for Object:prototype

Description

Object prototype from instance

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 .j  a v  a 2 s. co  m
var a = { n: 8, myObj: { i: 7 }};
var b = Object.create(a);
b.n = 10;
console.log(a.n);  // still 8
console.log(b.n);  // 10
b.myObj.i = 15;
console.log(a.myObj.i);  // changed to 15!
console.log(b.myObj.i);  // 15
    }

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

Related Tutorials