javascript - 如何将函数添加到对象内的现有函数列表中
问题描述
我正在使用外部库,尤其是LittlePlanet.js:
function LittlePlanet (type = 'image', source) {
this.dragging = false;
...
}
LittlePlanet.prototype = Object.assign(Object.create(ImagePanorama.prototype), {
constructor: LittlePlanet,
registerMouseEvents: function () {
this.container.addEventListener('mousedown', this.onMouseDown.bind(this), {passive: true});
this.container.addEventListener('mousemove', this.onMouseMove.bind(this), {passive: true});
this.container.addEventListener('mouseup', this.onMouseUp.bind(this), { passive: true});
...
}
});
如何在registerMouseEvents
不覆盖预先存在的事件侦听器的情况下向属性添加另一个事件侦听器?
这是我尝试过的:
PANOLENS.LittlePlanet.prototype.registerMouseEvents = function () {
zoomOut.addEventListener("mousedown", this.onZoom.bind(this), false);
...
};
但这会覆盖预先存在的registerMouseEvent
事件侦听器。
解决方案
推荐阅读
- amazon-web-services - 多接口 EC2 实例 - 更改源/目标检查的问题
- swift - 无法在 Xcode 12.4 Simulator Watch Series 6 44mm 中的 WatchOS 7.2 上滚动颜色
- javascript - 无法与 bitcore 测试网连接,出现以下错误 525 Origin SSL Handshake Error
- java - 如何在java流中构建实体?
- apache-spark - 在项目记录器中捕获 PySpark 错误日志和回溯
- javascript - 将我的 canvasjs 图表转换为 chart.js 图表
- java - 未调用handleFrame
- java - Netbeans SLF4J:类路径包含多个 SLF4J 绑定
- rspec - Rspec - “所有示例都被过滤掉了”
- javascript - 我无法导出在我的一个反应组件中创建的数组