Skip to content

Instantly share code, notes, and snippets.

@arv
Created November 16, 2012 20:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arv/4090806 to your computer and use it in GitHub Desktop.
Save arv/4090806 to your computer and use it in GitHub Desktop.
Object.prototype.$super = function() {
var func = arguments.callee.caller;
var name = func.foundName_;
if (!name) {
for (var p in this) {
if (this[p] == func) {
name = p;
break;
}
}
func.foundName_ = name;
}
// Set up function to baseValue chain.
if (!func.baseValue_) {
for (var obj = Object.getPrototypeOf(this); obj; obj = Object.getPrototypeOf(obj)) {
if (Object.prototype.hasOwnProperty.call(obj, name)) {
obj[name].baseValue_ = obj;
obj[name].foundName_ = name;
}
}
}
var baseProto = Object.getPrototypeOf(func.baseValue_);
return baseProto[name].call(this);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment