Skip to content

Instantly share code, notes, and snippets.

@antyakushev
Last active August 29, 2015 14:14
Show Gist options
  • Save antyakushev/2d7fce5da410f9eb2e26 to your computer and use it in GitHub Desktop.
Save antyakushev/2d7fce5da410f9eb2e26 to your computer and use it in GitHub Desktop.
Coffee Script debug functions
augment: (withFn) ->
for name of @
fn = @[name]
if typeof fn is 'function'
@[name] = ((name, fn) ->
console.log "augmenting " + name
args = arguments
->
withFn.apply @, args
return fn.apply @, arguments
)(name, fn)
stackTrace: ->
e = new Error('err');
stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '')
.replace(/^\s+at\s+/gm, '')
.replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@')
.split('\n')
console.log stack
debug: ->
@augment (name, fn) ->
console.log "calling " + name
@stackTrace() if name is 'clear'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment