Re:Announcing the first release of batman.js
by MatthewPhillips on Wednesday August 24, 2011 @11:55PM
(#2923716)
This is the way JS devs have been hacking inheritance for a long time. That's irrelevant though, we're not comparing CS to Backbone, we're comparing Batman.js to Backbone.
Backbone handles the messy inheritance code for you. Batman.js relies on CS for that, but a JS dev is going to have to write the inheritance code by hand. I posted the JS equivalent of their example in this thread, it's nasty.
Re:Announcing the first release of batman.js
by jashkenas on Thursday August 25, 2011 @12:14AM
(#2923744)
It is indeed nasty ... and for that extra nastiness, above and beyond the inheritance pattern listed above, you get:
* A subclass that inherits the parent's implementation of the constructor function, unless overridden.
* A named function for your class object, without IE scope leaks.
* A way to call super that's as easy as `super()`.
* Inheritance of the parent's own properties (unfortunately via copying).
* ... which enables helpful metaprogramming within class bodies. For example, Batman's own `event` decorator:
use: @event (times) ->
return false unless ...
Both simply create an empty object to serve as the prototype (calling new without actually running your constructor), set up the prototype chain correctly, and stash a reference so that calling `super` is easier later on.
If "Child" and "Parent" are constructor functions (class objects), then the basic pattern is this:
Fun.