Skip to content

Instantly share code, notes, and snippets.

@wenzhixin
Created December 11, 2014 12:05
Show Gist options
  • Save wenzhixin/80e959abe2e2edd6c437 to your computer and use it in GitHub Desktop.
Save wenzhixin/80e959abe2e2edd6c437 to your computer and use it in GitHub Desktop.
// a.js
var A = function () {
};
A.prototype.a = function (a) {
return a;
};
A.prototype.b = function (b) {
return b;
};
// b.js
var B = function () {
};
B.prototype.b = function (b) {
return b;
};
B.prototype.c = function (c) {
return c;
};
// c.js
var C = function () {
};
C.prototype.c = function (c) {
return c;
};
C.prototype.d = function (d) {
return d;
};
[A, B, C].forEach(function (Clazz) {
for (var key in Clazz.prototype) {
var func = Clazz.prototype[key];
if (typeof func === 'function') {
var proxy = Clazz.prototype[key];
Clazz.prototype[key] = function () {
console.log(arguments);
var result = proxy.apply(this, arguments);
console.log(result);
return result;
};
}
}
});
// app.js
var a = new A();
a.a(1);
a.b(2);
var b = new B();
b.b(3);
b.c(4);
var c = new C();
c.c(5);
c.d(6);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment