Skip to content

Instantly share code, notes, and snippets.

@ggoodman
Created December 19, 2011 19:46
Show Gist options
  • Save ggoodman/1498564 to your computer and use it in GitHub Desktop.
Save ggoodman/1498564 to your computer and use it in GitHub Desktop.
Trace calls to your deeply-nested CoffeeScript methods
### traced.coffee
#
## Usage:
# class app.Class
# method1: traced "app.Class.method1", ->
# "return value of method1"
#
# method2: traced "app.Class.method2, (prefix) ->
# prefix + @method1()
#
# inst = new app.Class
# inst.method2("Prefix passed in")
#
## Result:
# > app.Class.method2 Prefix passed in
# >> app.Class.method1
# << app.Class.method1 return value of method1
# < app.Class.method2 Prefix passed inreturn value of method1
#
###
traced = do ->
depth = 0
repeat = (chr, n) -> new Array(n).join(chr)
(name, func) ->
(args...) ->
console.log repeat(">", ++depth), name, args
ret = func.apply(@, args)
console.log repeat("<", --depth), name, ret
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment