Created
July 22, 2012 08:47
-
-
Save kenegozi/3158946 to your computer and use it in GitHub Desktop.
javascript-proxying-example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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