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

Actually, I don't understand CoffeeScript. The example from the post doesn't even compile, using CoffeeScript 1.3.3:

    do (methods = ['remove', 'show', 'hide', 'stop']) ->
      for method in methods do ->
        Frame.prototype[method] = ->
          for element in elements do ->
            this[element][method]()

    Error: In test.coffee, Parse error on line 5: Unexpected 'OUTDENT'


I noticed that while reading it as well, as it's one of the (few) things that bugs me when writing coffeescript. It should have a 'then' between the conditions of each 'for' loop and 'do', because that is the only way to include the loop body (the 'do' statement) on the same line as the loop conditions.

   do (methods = ['remove', 'show', 'hide', 'stop']) ->
      for method in methods then do ->
        Frame.prototype[method] = ->
          for element in elements then do ->
            this[element][method]()


Never used coffee script, but is it missing a new-line at the end of the file?

My intuition says it's reaching the end of the file before reaching the "end-of-block" unindent characters. I mean, the tokeniser should output enough outdents to get you back to indent-level zero when it hits EOF, but maybe it's not?




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

Search: