|
|
|
|
|
by jashkenas
5419 days ago
|
|
For the record, the way that CoffeeScript does inheritance and the way that Backbone's "extend" does inheritance is almost literally exactly the same thing. 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: var ctor = function(){};
ctor.prototype = Parent.prototype;
Child.prototype = new ctor;
Child.prototype.constructor = Child;
Fun. |
|
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.