私が作成している小さなキャンバス ライブラリのイベント クラスを作成しようとしています!
これは私がこれまでに持っているものです。
function Events() {
};
Events.prototype.addEvents = function() {
this.mousemove = false;
this.onMousemove = function() {
if (this.mousemove) {
this.mousemove();
}
};
this.mousedown = false;
this.onMousedown = function() {
if (this.mousedown) {
this.mousedown();
}
};
this.mouseup = false;
this.onMouseup = function() {
if(this.mouseup) {
this.mouseup();
}
};
this.click = false;
this.onClick = function() {
if (this.click) {
this.click();
}
};
this.on = function(type, callback) {
};
};
私ができないことは、イベントを割り当てたい他のオブジェクトにこれを追加することです。たとえば、別のオブジェクトは draw メソッドを持つ単純な長方形です。
function Rect() {
this.draw = function(context) {
// code
};
};
// How can I add Events prototype properties to Rect? I have tried...
// Rect.prototype = new Object.create(Events.prototype);
// Rect.prototype = Object.create(new Events.prototype);
私は基本的に、イベントプロトタイプがそのすべてのプロパティを、イベントを持ちたい別のオブジェクトに与えることを望んでいますか?
ありがとうございます。