Javascript examples for Object:Object Method
A class with method overriding
<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>