Javascript examples for Object:prototype
Use prototype to add method to object
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from w ww .j a va 2 s. c o m*/ function Obj(n){ this.name = n; } Obj.prototype.disp = function(){ console.log(this.name); }; var l1=new Obj("one"); var l2=new Obj("two"); var lessons=[l1,l2]; lessons[0].disp(); console.log(lessons[0].name); } </script> </head> <body> </body> </html>