Sharing methods and properties between Object classes - Javascript Object

Javascript examples for Object:Object Property

Description

Sharing methods and properties between Object classes

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.ja  v a2s .co m
function MyClass(){
}
var myClass = new MyClass();
myClass.constructor.prototype.sayHi = function(){
   console.log("Hi");
};
var myClass2 = new MyClass();
myClass2.sayHi();
    }

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

Related Tutorials