Eine Skim der Zepto.js Quelle zeigt es eine $.extend
Methode hat, die arbeiten können, aber es ist eher eine Verschmelzung von zwei Objekten Implementierung als ein traditionelles Vererbungsmodell (die Dinge wie Super Accessoren bieten würde.)
CoffeeScript generiert den Code, der für das typische Vererbungsmodell erforderlich ist.
in:
class Person
constructor: (@name) ->
class Ninja extends Person`
aus:
var Ninja, Person;
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
child.__super__ = parent.prototype;
return child;
};
Person = function() {
function Person(name) {
this.name = name;
}
return Person;
}();
Ninja = function() {
function Ninja() {
Ninja.__super__.constructor.apply(this, arguments);
}
__extends(Ninja, Person);
return Ninja;
}();