Skip to content

Instantly share code, notes, and snippets.

@mmaelzer
Created September 23, 2014 19:51
Show Gist options
  • Save mmaelzer/92570feecd925d8eb827 to your computer and use it in GitHub Desktop.
Save mmaelzer/92570feecd925d8eb827 to your computer and use it in GitHub Desktop.
Logging on an object's methods
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