Create class and then create object from it with new operator - Javascript Object

Javascript examples for Object:Constructor

Description

Create class and then create object from it with new operator

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 w  w  .  j a v  a  2  s  .co  m*/
function Developer(skill) {
    this.skill = skill;
    this.says = function() {
        console.log(this.skill + ' rocks!');
    }
}
var john = new Developer('Ruby');
john.says();
    }

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

Related Tutorials