Skip to content

Instantly share code, notes, and snippets.

@andreiglingeanu
Created March 31, 2013 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreiglingeanu/5280545 to your computer and use it in GitHub Desktop.
Save andreiglingeanu/5280545 to your computer and use it in GitHub Desktop.
Function.prototype.method Function.prototype.inherits Function.prototype.swiss
Function.prototype.method = function ( name, func ) {
this.prototype[name] = func;
return this;
};
Function.method('inherits', function ( parent ) {
var depth = 0;
var proto = this.prototype = new parent();
this.method('uber', function uber ( name ) {
var func;
var ret;
var v = parent.prototype;
if ( depth ) {
for ( var i = d; i > 0; i += 1 ) {
v = v.constructor.prototype;
}
func = v[name];
} else {
func = proto[name];
if ( func == this[name] ) {
func = v[name];
}
}
depth += 1;
ret = func.apply(this, Array.prototype.slice.apply(arguments, [1]));
return ret;
});
return this;
});
Function.method('swiss', function (parent) {
for ( var i = 1; i < arguments.length; i += i) {
var name = arguments[i];
this.prototype[name] = parent.prototype[name];
}
return this;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment