Created
September 11, 2013 23:02
-
-
Save BernardoSilva/6530971 to your computer and use it in GitHub Desktop.
example of javascript class definition and Inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JavaScript Class Definition and Inheritance | |
function BaseClass() { | |
//BaseClass constructor code goes here | |
} | |
BaseClass.prototype.getName = function() { | |
return "BaseClass"; | |
} | |
function SubClass() { | |
//SubClass constructor code goes here | |
} | |
//Inherit the methods of BaseClass | |
SubClass.prototype = new BaseClass(); | |
//Override the parent's getName method | |
SubClass.prototype.getName = function() { | |
return "SubClass"; | |
} | |
//Alerts "SubClass" | |
alert(new SubClass().getName()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment