Created
February 6, 2014 17:28
-
-
Save sayjava/8848782 to your computer and use it in GitHub Desktop.
javascript 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
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