gpt4 book ai didi

javascript - underscore.js 解除绑定(bind)

转载 作者:行者123 更新时间:2023-11-29 20:17:55 26 4
gpt4 key购买 nike

我很乐意解除绑定(bind):

$("body").mousemove(_.bind(this.mousemove, this));

由于 backbone.js 和 raphael.js 之间的复杂混合,我需要通过 underscore.js 进行绑定(bind):

var NodeView = Backbone.View.extend({

dx: 0,
dy: 0,

click: function(event){
alert('hello')
},
mousedown: function(event){
this.dx = event.pageX - this.el.attr('x');
this.dy = event.pageY - this.el.attr('y');
this.el.attr({fill: "#0099FF"});

$("body").mousemove(_.bind(this.mousemove, this));
},
mousemove: function(event){
this.el.attr({ x: event.pageX - this.dx,
y: event.pageY - this.dy});
},
mouseup: function(event){
this.el.attr({fill: "#EEEEEE"});
$("body").mousemove(_.bind(this.mousenotmove, this));
},

render: function(){
this.el = canvas.rect(this.model.get('xPos'), this.model.get('yPos'), 50, 50).attr({
fill: "#EEEEEE",
stroke: "none",
cursor: "move"
});

$(this.el.node).mousedown(_.bind(this.mousedown, this));
$(this.el.node).mouseup(_.bind(this.mouseup, this));

return this;
}
});

有什么建议吗?

最佳答案

感谢@Pointy(谢谢 :D):

解决方案很简单:$("body").unbind("mousemove");

查看第一篇文章中的评论。

关于javascript - underscore.js 解除绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5595327/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com