AmpersandJS/ampersand-state — pull request #22 by nathanstitt (2014-06-30 14:43:54+00:00)
Title: Document incompatibility with Coffeescript

I'm not sure it should be mentioned so prominently, so feel free to reject and point me in a better location.

Coffeescript has a built-in `extend` method that is compatible with Backbone's extend. Because of that, you can write Coffeescript "Classes" that inherit from Backbone Views/Models/Collections. i.e.

class Foo extends Backbone.View
constructor: (options)->
super

render: ->
view stuff
super

And it all "just works". About the only advantage of writing code in this fashion is the handy use of "super" to call the overwritten method.

Writing code in this fashion with Ampersand Views breaks in non-obious ways. No exceptions are thrown, things just don't work correctly.

What happens is that Coffeescript will call it's built-in extend method, which copies all the functions onto the prototype, and records the parent information for super, but that's about it. It never calls AmpersandState.extend, so none of the special prototype objects are created, leading to strange behavior later. I noticed it when I couldn't get subviews to render at all.

For my purposes, this isn't a deal-breaker. I've always been ambivalent about the Coffeescript's class usage with Backbone, so will be fine going back to the explicit extend pattern. For others, it probably will be since it's hard to let `super` go.