Javascript examples for Object:Constructor
Create a class with constructor
<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>