Ich spiele mit Typoskript um, und ich habe ein paar bekomme funktionelle Mixins , Eventableund Settable, dass ich zu einer mixin möchte ModelKlasse (so tun , es ist so etwas wie ein Backbone.js Modell):
function asSettable() {
this.get = function(key: string) {
return this[key];
};
this.set = function(key: string, value) {
this[key] = value;
return this;
};
}
function asEventable() {
this.on = function(name: string, callback) {
this._events = this._events || {};
this._events[name] = callback;
};
this.trigger = function(name: string) {
this._events[name].call(this);
}
}
class Model {
constructor (properties = {}) {
};
}
asSettable.call(Model.prototype);
asEventable.call(Model.prototype);
Der obige Code funktioniert gut, aber würde nicht kompilieren , wenn ich versuche , wie eine des Mixed-in Verfahren zu verwenden (new Model()).set('foo', 'bar').
Ich kann dieses Problem umgehen, indem
- Hinzufügen von
interfaceErklärungen für die Mixins - erklärt dummy
get/set/on/triggerMethoden in derModelErklärung
Gibt es eine saubere Art und Weise um die Dummy-Erklärungen?













