Index: lib/events.js |
diff --git a/lib/events.js b/lib/events.js |
index 2f567ce25fd5b05481db7962735bcd2b3fb65767..db53bf8c82c2807c81d64563d1c7362c03962578 100644 |
--- a/lib/events.js |
+++ b/lib/events.js |
@@ -34,7 +34,7 @@ exports.EventEmitter.prototype = { |
* @param {string} name |
* @param {function} listener |
*/ |
- on: function(name, listener) |
+ on(name, listener) |
{ |
if (name in this._listeners) |
this._listeners[name].push(listener); |
@@ -48,7 +48,7 @@ exports.EventEmitter.prototype = { |
* @param {string} name |
* @param {function} listener |
*/ |
- off: function(name, listener) |
+ off(name, listener) |
{ |
let listeners = this._listeners[name]; |
if (listeners) |
@@ -62,10 +62,10 @@ exports.EventEmitter.prototype = { |
/** |
* Adds a one time listener and returns a promise that |
* is resolved the next time the specified event is emitted. |
- * |
+ * @param {String} name |
* @return {Promise} |
*/ |
- once: function(name) |
+ once(name) |
{ |
return new Promise(resolve => |
{ |
@@ -85,7 +85,7 @@ exports.EventEmitter.prototype = { |
* @param {string} name |
* @return {function[]} |
*/ |
- listeners: function(name) |
+ listeners(name) |
{ |
let listeners = this._listeners[name]; |
return listeners ? listeners.slice() : []; |
@@ -97,14 +97,10 @@ exports.EventEmitter.prototype = { |
* @param {string} name |
* @param {...*} [arg] |
*/ |
- emit: function(name) |
+ emit(name, ...args) |
{ |
- let args = []; |
- for (let i = 1; i < arguments.length; i++) |
- args.push(arguments[i]); |
- |
let listeners = this.listeners(name); |
for (let listener of listeners) |
- listener.apply(null, args); |
+ listener(...args); |
} |
}; |