| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 resolve(); | 75 resolve(); |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 this.on(name, listener); | 78 this.on(name, listener); |
| 79 }); | 79 }); |
| 80 }, | 80 }, |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * Returns a copy of the array of listeners for the specified event. | 83 * Returns a copy of the array of listeners for the specified event. |
| 84 * | 84 * |
| 85 * @param {string} name | |
| 85 * @return {function[]} | 86 * @return {function[]} |
| 86 */ | 87 */ |
| 87 listeners: function(name) | 88 listeners: function(name) |
|
Sebastian Noack
2016/03/24 11:07:13
node.js has that method as well. We need it to reu
| |
| 88 { | 89 { |
| 89 let listeners = this._listeners[name]; | 90 let listeners = this._listeners[name]; |
| 90 return listeners ? listeners.slice() : []; | 91 return listeners ? listeners.slice() : []; |
| 91 }, | 92 }, |
| 92 | 93 |
| 93 /** | 94 /** |
| 94 * Calls all previously added listeners for the given event name. | 95 * Calls all previously added listeners for the given event name. |
| 95 * | 96 * |
| 96 * @param {string} name | 97 * @param {string} name |
| 97 * @param {...*} [arg] | 98 * @param {...*} [arg] |
| 98 */ | 99 */ |
| 99 emit: function(name) | 100 emit: function(name) |
| 100 { | 101 { |
| 101 let args = []; | 102 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
| |
| 102 for (let i = 1; i < arguments.length; i++) | 103 for (let i = 1; i < arguments.length; i++) |
| 103 args.push(arguments[i]); | 104 args.push(arguments[i]); |
| 104 | 105 |
| 105 let listeners = this.listeners(name); | 106 let listeners = this.listeners(name); |
| 106 for (let listener of listeners) | 107 for (let listener of listeners) |
| 107 listener.apply(null, args); | 108 listener.apply(null, args); |
| 108 } | 109 } |
| 109 }; | 110 }; |
| LEFT | RIGHT |