catvm/CatVm2/browser/EventTarget.js
Big1moster d843fcb236 dsf
2023-02-06 11:36:48 +08:00

34 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var EventTarget = function EventTarget() { // 构造函数
};
catvm.safefunction(EventTarget);
// 因为EventTarget是构造函数而我们要的是原型因此需要先hook EventTarget.prototype设置下原型的名字否则它会使用父亲的名字
Object.defineProperties(EventTarget.prototype, {
[Symbol.toStringTag]: {
value: "EventTarget",
configurable: true
}
})
EventTarget.prototype.addEventListener = function addEventListener(type,callback) {
debugger; //debugger的意义在于检测到是否检测了该方法
if(!(type in catvm.memory.listeners)){
catvm.memory.listeners[type] = [];
}
catvm.memory.listeners[type].push(callback);
};
catvm.safefunction(EventTarget.prototype.addEventListener);
EventTarget.prototype.dispatchEvent = function dispatchEvent() {
debugger;
};
catvm.safefunction(EventTarget.prototype.dispatchEvent);
EventTarget.prototype.removeEventListener = function removeEventListener() {
debugger;
};
catvm.safefunction(EventTarget.prototype.removeEventListener);
// EventTarget = catvm.proxy(EventTarget);
// EventTarget.prototype = catvm.proxy(EventTarget.prototype);