Skip to content

Instantly share code, notes, and snippets.

@BernardoSilva
Created September 11, 2013 23:02
Show Gist options
  • Save BernardoSilva/6530971 to your computer and use it in GitHub Desktop.
Save BernardoSilva/6530971 to your computer and use it in GitHub Desktop.
example of javascript class definition and Inheritance
// 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