5 ms·
Gist to add CoffeeScript friendly argument order to Underscore.js
- roryokane 14y agoFor others who were confused like me: the title refers to argument order that is easy to write in CoffeeScript, not the (non-existent) "friendly argument order" feature of CoffeeScript.
- jimtla 14y agoOops that was meant to be (CoffeeScript friendly) argument order, not CoffeeScript (friendly argument order). English needs better operator precedence. Thanks
- alecperkins 14y agoA hyphen would be useful here: “CoffeeScript-friendly argument order”.
- jQueryIsAwesome 14y agoI agree, lets make a pull request to... after a little research looks like there is no language regulator for English (http://en.wikipedia.org/wiki/List_of_language_regulators http://en.wikipedia.org/wiki/List_of_language_regulators) :/
- deleted 14y ago[deleted]
- Perceptes 14y agoYou can also call the original method without the ugly leading comma like this: _.throttle( -> console.log("Foo") 500 )
- sic1 14y agoNice, got me thinkin and tried this: _.throttle -> console.log("Foo") , 500 And it works!
- Perceptes 14y agoThat's what the author of this Gist was trying to avoid.
- jewel 14y agoIs there any reason coffeescript can't be extended to support the same thing without parentheses? That feels fairly natural to me since it's similar to the object literal syntax. Edit: Couldn't find that this has ever been suggested before, so I created a github issue: https://github.com/jashkenas/coffee-script/issues/2307 https://github.com/jashkenas/coffee-script/issues/2307
- shaunxcode 14y agoI dig what you are saying but after some reflection decided I would rather see kv args. Here is a gist to accomplish that: https://gist.github.com/2625081 https://gist.github.com/2625081 (wish there was simple way to introspect a fn and get its arg names, but saying that a lot of underscore functions have dynamic arities so this only makes sense for specific functions anyway) $(window).scroll _.throttleKV func: -> console.log "This print's at most every 500ms" wait: 500 Nice thing about that is you don't have to rememeber arg order (though you do have to remember the kv names). In coffee though you have less commas, feels nearly smalltalkish.
- jimtla 14y agoVery cool - I like that alot. There's probably a way to programmatically add that for every underscore function, but there's probably not a _good_ way...
- stilist 14y agoIn the past few months I’ve moved to named functions for any timers/event bindings/callbacks longer than a single statement. Keeps things more manageable in general, and as a bonus, sidesteps this issue. Spaghetti’s tasty, but belongs on your plate, not your computer.