A class with method overriding - Javascript Object

Javascript examples for Object:Object Method

Description

A class with method overriding

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() {//ww w .java  2  s  . co  m
function Base(){}
Base.prototype.foo = function() { 
   console.log("base"); 
};

function Derived() {}

Derived.prototype = new Base();
Derived.prototype.foo = function() { 
   console.log("overridden"); 
};

var b = new Base();
var d = new Derived();

b.foo();
d.foo();
    });

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

Related Tutorials