Skip to content

Instantly share code, notes, and snippets.

@kenegozi
Created July 22, 2012 08:47
Show Gist options
  • Save kenegozi/3158946 to your computer and use it in GitHub Desktop.
Save kenegozi/3158946 to your computer and use it in GitHub Desktop.
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