Skip to content

Instantly share code, notes, and snippets.

@madbook
Last active December 21, 2015 20:00
Show Gist options
  • Save madbook/6358595 to your computer and use it in GitHub Desktop.
Save madbook/6358595 to your computer and use it in GitHub Desktop.
replace `obj` with a module object. This wraps every method of that object that dumps nested, collapsible console logs any time those methods are called. logs include arguments, return value, and execution time.
for (i in obj)
if (typeof obj[i] === 'function' && i !== 'toString')
(function (method) {
var fnc = obj[method]
obj[method] = function () {
var x
console.groupCollapsed(this + " -> " + method)
console.dir(this)
console.dir(arguments)
console.time(method + ' time')
console.log(x = fnc.apply(this, arguments))
console.timeEnd(method + ' time')
console.groupEnd()
return x
}
})(i)
@madbook
Copy link
Author

madbook commented Aug 28, 2013

  • edited to make the wrapper functions return the value from the real functions.
  • for readability, i recommend give your object a custom toString method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment