zepto.jsには、クラスを追加したり、サブクラスで拡張したりするためのメソッドがありますか?
関連する質問は次のとおりです。Coffeescriptは、実際には、特定のメソッドを持つプロトタイプのようなライブラリを必要とせずに、クラスを記述して拡張する機能を提供しますか?
zepto.jsには、クラスを追加したり、サブクラスで拡張したりするためのメソッドがありますか?
関連する質問は次のとおりです。Coffeescriptは、実際には、特定のメソッドを持つプロトタイプのようなライブラリを必要とせずに、クラスを記述して拡張する機能を提供しますか?
Zepto.js ソースをざっと見てみると、機能する可能性のある$.extend
メソッドがあることがわかりますが、従来の継承モデル (スーパー アクセサーなどを提供する) よりも、2 つのオブジェクト実装のマージに近いものです。
CoffeeScript は、求めるかもしれないし求めないかもしれない典型的な継承モデルを提供するために必要なコードを生成します。
の:
class Person
constructor: (@name) ->
class Ninja extends Person`
アウト:
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;
}();