내가 만들고있는 작은 캔버스 라이브러리에 대한 이벤트 클래스를 만들려고합니다!자바 스크립트에서 이벤트 기본 클래스를 만드는 방법은 무엇입니까?
이것은 내가 지금까지 무엇을 가지고,
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);
기본적으로 이벤트 프로토 타입을 사용하여 이벤트를 원하는 다른 객체에 모든 속성을 제공하고 싶습니다.
감사합니다.
설명을 좀 더 명확히하기 위해 편집되었습니다.처음으로 너무 빠르게 입력했고 임시 생성자 F()를 사용하면 얻을 수있는 이점을 잘못 설명했습니다. –