Index: lib/events.js |
=================================================================== |
--- a/lib/events.js |
+++ b/lib/events.js |
@@ -80,6 +80,18 @@ |
}, |
/** |
+ * Returns a copy of the array of listeners for the specified event. |
+ * |
+ * @param {string} name |
+ * @return {function[]} |
+ */ |
+ listeners: function(name) |
+ { |
+ let listeners = this._listeners[name]; |
+ return listeners ? listeners.slice() : []; |
+ }, |
+ |
+ /** |
* Calls all previously added listeners for the given event name. |
* |
* @param {string} name |
@@ -87,16 +99,12 @@ |
*/ |
emit: function(name) |
{ |
- let listeners = this._listeners[name]; |
- if (listeners) |
- { |
- let args = []; |
- for (let i = 1; i < arguments.length; i++) |
- args.push(arguments[i]); |
+ let args = []; |
kzar
2016/03/24 11:29:53
Any reason why you now create the args array even
Sebastian Noack
2016/03/24 11:33:27
To keep the logic simple. Before we had to handle
kzar
2016/03/24 11:35:58
Fair enough I guess
|
+ for (let i = 1; i < arguments.length; i++) |
+ args.push(arguments[i]); |
- let currentListeners = listeners.slice(); |
- for (let listener of currentListeners) |
- listener.apply(null, args); |
- } |
+ let listeners = this.listeners(name); |
+ for (let listener of listeners) |
+ listener.apply(null, args); |
} |
}; |