Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For the record, CoffeeScript tries to help ameliorate all of these "warts".

* "Hoisting under the hood" -- Function declarations vs. function expressions don't get you into hoisting trouble, because there are no function declarations, and every value is an expression.

* Explicit block scopes can be (more easily) created with:

    do (x, y) ->
      # here, x and y are captured in a new scope.
* "What does 'this' mean?" -- The value of "this" can be fixed lexically, by using the bound function (fat arrow) =>, instead of the normal function arrow: ->. Look ma, no "var that" or "var self":

    $.getJSON url, (resp) =>
      this.setResponse resp
* "Fixing Arguments" -- Function arguments are always available as an array instead of an Arguments object.

    myVariadicFunction = (args...) ->
      # here, "args" is an Array.
* "Avoiding truthiness" -- There is no "==" and "!=" in CoffeeScript, all equality is strict equality. For the one case where double equals is useful in JS, you have the existential operator...

  if a is b
    # here, a === b.


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

Search: