Trying to refactor a simple function:
// arr - array of objects with functions
function eventNotify(arr, event) {
for (var i = 0; i < arr.length; i++) {
var a = arr[i];
if (typeof a[event] === 'function') {
a[event]();
}
}
}
into this one:
function eventNotify(arr, event) {
for (var i = 0; i < arr.length; i++) {
var a = arr[i][event];
if (typeof a === 'function') {
a();
}
}
}
I'm stuck trying to comprehend how such change manages to break all my tests.
How is it possible that the second implementation is functionally different from the first one?
I even tried to split the use of indexes, thinking that maybe it is treated as a 3D array:
var a = arr[i];
a = a[event];
But no, this makes no difference.
Please somebody point out what on earth am I changing in the logic of the algorithm there! I'm wracking my brain over this one now.
I'm testing it under Node.js 10.9