Using Object.create instead of Constructors for inheritance - Javascript Object

Javascript examples for Object:Constructor

Description

Using Object.create instead of Constructors for inheritance

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  w w w. j  ava 2s. com

var my = Object.create( Object.prototype, {
    oldProp: { value: 'new value', writable: true, enumerable: true}
});
my.oldProp = "this is a test";
console.log(my.oldProp);
for (var k in my) 
   console.log(my[k]);

    }

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

Related Tutorials