

Gist to add CoffeeScript friendly argument order to Underscore.js - jimtla
https://gist.github.com/2624704

======
shaunxcode
I 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>
(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
Very 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
In 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.

------
Perceptes
You can also call the original method without the ugly leading comma like
this:

    
    
        _.throttle(
          ->
            console.log("Foo")
          500
        )

~~~
sic1
Nice, got me thinkin and tried this:

    
    
      _.throttle ->
          console.log("Foo")
        , 500
    

And it works!

~~~
Perceptes
That's what the author of this Gist was trying to avoid.

------
roryokane
For 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
Oops that was meant to be (CoffeeScript friendly) argument order, not
CoffeeScript (friendly argument order). English needs better operator
precedence.

Thanks

~~~
alecperkins
A hyphen would be useful here: “CoffeeScript-friendly argument order”.

