Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
function createBase(){
// This function recursively and distructively
// merges the guest object onto the host object
function merge(host, guest) {
// cycle through guest's properties
for(var prop in guest) {
// if the property is an object then run
// the merge on it or just copy it over
host[prop] = (typeof guest[prop] === 'object') ?
merge(host[prop], guest[prop]) :
return host;
// This function processes the declaritave function
// as well as manages the extension
function extend(factoryFunction){
// run the factoryFunction to get the declaration object
var properties = factoryFunction(),
// extract the constructor function reference
BaseClass = properties.init,
// extract the super class reference
SuperClass = this;
// copy extend function across
BaseClass.extend = SuperClass.extend;
// create the inheritance heirarchy
BaseClass.prototype = Object.create(SuperClass.prototype);
// merge the new properties with those given from inheritance
merge(BaseClass.prototype, properties);
// return the class ready for use.
return BaseClass;
function Base(){}
Base.extend = extend;
return Base;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment