Create a class with constructor - Javascript Object

Javascript examples for Object:Constructor

Description

Create a class with constructor

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   ww  w. j  a  v  a 2s  .c o m*/
function Rec(w,h) {
    this.setW=function(newW){
        w=newW;
    }
    this.area=function(){
        return w*h;
    }
}
var rec=new Rec(5,6);
rec.setW(2);
//alert("W",rect.w);
console.log(rec.area())
    }

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

Related Tutorials