Created
September 23, 2014 19:51
-
-
Save mmaelzer/92570feecd925d8eb827 to your computer and use it in GitHub Desktop.
Logging on an object's methods
This file contains hidden or 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 protos = Object.getPrototypeOf(this); | |
Object.keys(protos).forEach(function(key) { | |
if (typeof this[key] === 'function' && key !== 'constructor') { | |
var fn = this[key]; | |
this[key] = function() { | |
var name = this.name ? this.name + '.' : ''; | |
var identity = name + key; | |
console.time(identity); | |
var ret = fn.apply(this, arguments); | |
console.timeEnd(identity); | |
return ret; | |
}; | |
} | |
}, this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment