ES6将参数传递给从回调函数调用的函数
ES6 Pass paremeter to function which called from callback function
我正试图将参数传递给回调函数中调用的函数,这是否可能与es6或javascript?下面是示例:
sprite.on('mousedown', this.onDragStart)
.on('touchstart', this.onDragStart)
.on('mouseup', this.onDragEnd)
.on('mouseupoutside', this.onDragEnd)
.on('touchend', this.onDragEnd)
.on('touchendoutside', this.onDragEnd)
.on('mousemove', this.onDragMove);
.on('touchmove', this.onDragMove);
onDragStart(event) {
this.data = event.data;
this.alpha = 0.5;
this.dragging = true;
this.selected = true;
}
onDragMove(arg) {
if (this.dragging) {
var newPosition = this.data.getLocalPosition(this.parent);
arg.m_orange.setPosition(newPosition.x, newPosition.y);
}
}
onDragEnd() {
this.alpha = 1;
this.dragging = false;
this.data = null;
this.selected = false;
}
我想传递一个参数函数onDragMove,这是调用只有当鼠标移动,这是可能的吗?
如果没有,有没有其他方法传递父类的关键字this到onDragMove函数?
你也可以使用es6的箭头函数来代替bind。
on('mousemove', (ev) => this.onDragMove(ev, otherArg))
你可以使用Function.prototype.bind:
on('mousemove', this.onDragMove.bind(thisArg, otherArg))
相关文章:
- 如何从模块链中调用函数.导出到节点中
- 是否可以将一个函数输入连接到另一个函数调用的文本
- 从同一原型和上下文中的另一个函数调用函数
- 如何在javascript中从另一个函数调用函数
- 如何使用与之前调用的布尔值相反的函数调用函数
- 煎茶架构师 从其他函数调用函数
- Java Script简单函数调用(函数不在作用域中)
- 从原型函数调用函数
- 如何在同一命名空间内从函数B调用函数A
- 从具有相同组件的函数调用函数
- Node.js从其他函数调用函数不工作
- 从另一个函数调用函数- Javascript API
- 从对象内部的函数调用函数(对象字面值)
- 从同一个函数调用函数
- javascript中使用构造函数调用函数
- 在主脚本中创建一个JavaScript类函数调用函数
- 如何在Java脚本中从另一个函数调用函数
- 使用jquery和javascript从函数调用函数
- 从 javascript 函数调用 c# 函数
- 从同一控制器内的函数调用函数