Created
December 19, 2011 19:46
-
-
Save ggoodman/1498564 to your computer and use it in GitHub Desktop.
Trace calls to your deeply-nested CoffeeScript methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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