Chris Abrams

Front-end Engineer

The Coffeescript 1.5 change that wasnt mentioned but might affect your apps

By Chris Abrams

Yesterday was a frustrating day because of the Coffeescript 1.5 update. The apps that I work on use the Grunt team's contrib-coffee, which updated to 1.5 yesterday. I like many others immediately realized that the apps that once worked in 1.4 did not work in 1.5. And the worst part is that this change is not even documented in the change log or in any web sites that covered the change.

So what changed?

I used to be able to say this

    @view.subview 'tags', new RelatedTagsList
      collection: tags

and get this as the Javascript

    this.view.subview('tags', new RelatedTagsList({
      collection: tags
    }));

but now I get this instead.

    this.view.subview('tags', new RelatedTagsList)({
      collection: tags
    });

I had to update the project I was working on to do this

    @view.subview('tags', new RelatedTagsList({
      collection: tags
    }))

which isn't a huge change (and is very similar to the Javascript output), but was annoying to go find this in the code base.

Until this change, I had found the Coffeescript compiler to be quite reliable and predictable. I just wish this had been documented as it was a very tedious problem to figure out and resolve. It doesn't change my view on Coffeescript at all - it's still my preferred way of developing on the front-end.

Thanks to @davidkaneda for providing the above examples while working with Team Delicious yesterday.

Update (02/26)

It would also seem that this works, altough I'm not a huge fan of this style:

    @view.subview 'tags', new RelatedTagsList collection: tags, foo:bar

Update (03/01)

If you are using Grunt's contrib-coffee, it has now been modified to a major version instead of a minor.

comments powered by Disqus