Learn JavaScript Part 20: Inheritance

  1. <!DOCTYPE html>  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <title></title>  
  5. </head>  
  6. <body>  
  7.     <script id="javascript">  
  8.         function Computer(processor)  
  9.         {  
  10.             this.processor = processor;  
  11.         }  
  12.   
  13.         Computer.prototype.assemble = function () 
  14.         {  
  15.             alert(this.processor + " - computer is assembled");  
  16.         };  
  17.   
  18.         var pc = new Computer("i7");  
  19.         pc.assemble();   
  20.         var pcTest = pc instanceof Computer;  
  21.         alert(pcTest);  
  22.     </script>  
  23. </body>  
  24. </html> 

Output

i7 – computer is assembled