Skip to content

Instantly share code, notes, and snippets.

@rohozhnikoff
Last active August 29, 2015 14:06
Show Gist options
  • Save rohozhnikoff/54e79dcbfc327daf54c3 to your computer and use it in GitHub Desktop.
Save rohozhnikoff/54e79dcbfc327daf54c3 to your computer and use it in GitHub Desktop.
observe all methods calls
# hard to perfomance
className = getClassName(@)
newProto = {}
_(@__proto__).each((value, name) =>
newProto[name] = do =>
if typeof value is 'function'
return =>
consoleMe = ['>>', [className, name].join('.')]
consoleMe.push '| call with', arguments if arguments.length > 0
console.log.apply console, consoleMe
return value.apply(@, arguments)
else
return value
).value()
_(@__proto__).extend(newHash)
# move to external
getClassName = (instance) ->
funcNameRegex = /function (.{1,})\(/
results = (funcNameRegex).exec((instance).constructor.toString())
if(results && results.length > 1) then results[1] else ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment