You can bind multiple event handlers using the attach () method (or its alias jQuery, on ()). You can remove them using the detach () or off () function. Here's a modified example from the event handling documentation :
// Create a circle shaped path at the center of the view: var path = new Path.Circle({ center: view.center, radius: 25, fillColor: 'black' }); var shiftPath = function() { this.position += new Point(15,15); }; // When the mouse enters the item, set its fill color to red: path.attach('mouseenter', function() { this.fillColor = 'red'; }); path.on('mouseenter', shiftPath); // When the mouse leaves the item, set its fill color to black // and remove the mover function: path.on('mouseleave', function() { this.fillColor = 'black'; path.detach('mouseenter', shiftPath); });
If you want to install an event handler for all instances of an object type, it is best to create a factory function according to this answer .
source share