defining Constructor in Javascript - Javascript Object

Javascript examples for Object:Constructor

Description

defining Constructor in Javascript

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 a  va2 s . c  om*/
function my() {
    // This is contructor method
    console.log('hello world!');
    this.init();
}
my.prototype = {
    constructor: my,
    init: function() {
        console.log('hello world!');
    }
};
var my = new my();
    }

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

Related Tutorials