Last active
August 29, 2015 14:01
-
-
Save tal/70462593c883bc8a9485 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| callableWithNmaed = (fn) -> | |
| fn_s = fn.toString() | |
| if m = fn_s.match(/function[\w\s]*\((.*?)\)/) | |
| arg_names = m[1].split(/[\s,]+/) | |
| (args) -> | |
| call_args = for arg_name in arg_names | |
| args[arg_name] | |
| call_args.push args | |
| fn.apply(null, call_args) | |
| fn1 = (foo, bar) -> | |
| foo+bar | |
| fn2 = (bar, foo) -> | |
| foo+bar | |
| opts = {foo: 'foo', bar: 'bar'} | |
| console.log fn1.toString(), callableWithNmaed(fn1)(opts) | |
| console.log fn2.toString(), callableWithNmaed(fn2)(opts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment