Skip to content

Instantly share code, notes, and snippets.

@sayjava
Created February 6, 2014 17:28
Show Gist options
  • Save sayjava/8848782 to your computer and use it in GitHub Desktop.
Save sayjava/8848782 to your computer and use it in GitHub Desktop.
javascript inheritance.
var extender = function(initializer){
var parent = this;
var child = function(){
parent.apply(this,arguments);
if(initializer) initializer.apply(this,arguments);
}
var Surrogate = function(){this.constructor = child; };
Surrogate.prototype = parent.prototype;
child.prototype = new Surrogate();
child.__super__ = parent.prototype;
child.extend = semetric.extend;
return child;
}
// usage
var GenericModel = function(){}
GenericModel.extend = extender;
var SpecificModel = GenericModel.extend(function(data){
// do something with the nice data here.
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment