Skip to content

Instantly share code, notes, and snippets.

@kanghyojun
Created October 10, 2014 09:36
Show Gist options
  • Select an option

  • Save kanghyojun/61b3c24bcf72702c6f80 to your computer and use it in GitHub Desktop.

Select an option

Save kanghyojun/61b3c24bcf72702c6f80 to your computer and use it in GitHub Desktop.
Object.prototype.hijack = function(f) {
var o = this;
for(k in o) {
(function(key) {
if(o[key] instanceof Function) {
var t = o[key].clone();
o[key] = function() {
return f(o, key, t, arguments);
}
}
})(k);
}
};
Function.prototype.clone = function() {
var that = this;
var temp = function temporary() { return that.apply(this, arguments); };
for(var key in this) {
if (this.hasOwnProperty(key)) {
temp[key] = this[key];
}
}
return temp;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment