Get prototype of an object initialized with {} - Javascript Object

Javascript examples for Object:prototype

Description

Get prototype of an object initialized with {}

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 a v  a 2  s  .  c o  m
var foo = {};
foo.constructor.prototype.field1='FOO';
foo.constructor.prototype.method1=function(){ console.log(this.field1)};
var bar={field1:'this is a test'};
bar.prototype=Object.create(foo);
bar.method1();
    }

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

Related Tutorials