0

Is there a way to add (in a nice way, I mean to avoid multiple listener definitions) same event handler to few events? i.e.

element.on('event1 event2 event3').listen(handleEvents);

EDIT: I mean also generic events like focus, blur etc.

4

1 回答 1

4

你可以这样做:

['event1', 'event2', 'event3'].forEach((event) => 
    element.on[event].listen(handleEvents));

或者,您可以这样做:

[element.onBlur, element.onFocus].forEach((stream) => stream.listen(handleEvents));
于 2013-09-07T20:20:47.297 回答