我正在尝试为我正在制作的一个小画布库制作一个事件类!
这是我目前所拥有的
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) {
};
};
我现在不能做的是将它添加到我要为其分配事件的其他对象中。例如,另一个对象将是一个具有绘制方法的简单矩形。
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);
我基本上希望事件原型将它的所有属性提供给另一个我想要事件的对象?
谢谢你,我希望我说得通!!