Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save usergenic/189370 to your computer and use it in GitHub Desktop.
Save usergenic/189370 to your computer and use it in GitHub Desktop.
// We can't use super because it's apparently reserved in some JS implementations.
var superf = function(){};
function overload(object, methodName, callback){
var superMethod = object[methodName];
object[methodName] = function(){
var _superf = superf;
var me = this;
superf = function(){
return superMethod.apply(me, arguments);
}
var result = callback.apply(this, arguments);
superf = _superf;
return result;
};
}
a = {"m":function(a,b){return a+b;}};
print(a.m(1,2)); // 3
overload(a, "m", function(a,b){
return superf(a*10, b);
});
print(a.m(1,2)); // 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment