Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
javascript-proxying-example
var x = {
doThis : function() { console.log('doThis'); },
whatIsThat : function(i) { console.log('whatIsThis'); return 'that is ' + i; },
name : 'I am x'
};
for (methodName in x) {
var method = x[methodName];
if (typeof method !== 'function') continue;
x[methodName] = (function(method, methodName) {
return function() {
var before = new Date();
var result = method.apply(x, arguments);
var after = new Date();
console.log('method ' + methodName + ' took ' + (after - before) + ' milliseconds');
return result;
}
})(method, methodName);
}
x.doThis();
console.log(x.whatIsThat(2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.