admin 管理员组文章数量: 1086019
I am asking this mainly out of curiosity as it is possible to replicate code but being deep in rails at the minute, repetition makes me feel dirty and I can't find it in the docs.
Suppose I have a rect = fabric.Rect
and I wanted to add a listener for say, moving and modified that do the same thing:
rect.on('moving', function() {
console.log('moving or modified');
});
rect.on('modified', function() {
console.log('moving or modified');
});
is it possible to bine these in some way?
I'm very new to JS and so this could be a simple thing in JS that I've not e across yet but again, it's not mentioned in Fabric docs that I've seen.
I am asking this mainly out of curiosity as it is possible to replicate code but being deep in rails at the minute, repetition makes me feel dirty and I can't find it in the docs.
Suppose I have a rect = fabric.Rect
and I wanted to add a listener for say, moving and modified that do the same thing:
rect.on('moving', function() {
console.log('moving or modified');
});
rect.on('modified', function() {
console.log('moving or modified');
});
is it possible to bine these in some way?
I'm very new to JS and so this could be a simple thing in JS that I've not e across yet but again, it's not mentioned in Fabric docs that I've seen.
Share Improve this question asked Apr 19, 2014 at 10:45 DazBaldwinDazBaldwin 4,3233 gold badges43 silver badges44 bronze badges 3- use only one why you want to bine? – Yogesh Commented Sep 1, 2014 at 14:27
- 2 because they're two distinct events that may need the same action being performed when they are triggered. – DazBaldwin Commented Sep 2, 2014 at 11:13
- check the sequence of events after move there this modify trigger – Yogesh Commented Sep 9, 2014 at 14:36
1 Answer
Reset to default 9I'm a little late, but just in case anyone else has this problem - you just need to move your mon code into a function, and then pass key/value pairs to the on() function:
function doLog() {
console.log('moving or modified');
}
rect.on({
'moving': doLog,
'modified': doLog
});
本文标签: javascriptfabricjs assign event listener to an object for multiple eventsStack Overflow
版权声明:本文标题:javascript - fabric.js assign event listener to an object for multiple events - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744083952a2530772.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论