mirror of
https://github.com/Big1moster/catvm.git
synced 2025-04-12 11:37:13 +08:00
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
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);
|