Hacker News new | past | comments | ask | show | jobs | submit login
Gist to add CoffeeScript friendly argument order to Underscore.js (gist.github.com)
33 points by jimtla on May 6, 2012 | hide | past | favorite | 11 comments



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.


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...


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.


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

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


Is 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


Nice, got me thinkin and tried this:

  _.throttle ->
      console.log("Foo")
    , 500
And it works!


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


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.


Oops that was meant to be (CoffeeScript friendly) argument order, not CoffeeScript (friendly argument order). English needs better operator precedence.

Thanks


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


I 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) :/




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: