Skip to content

Commit

Permalink
Avoid mutating parameterArray
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-el committed Jan 23, 2025
1 parent c47703c commit 7e3f9af
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions trackers/javascript-tracker/src/in_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,9 @@ export function InQueueManager(functionName: string, asyncQueue: Array<unknown>)
fnTrackers[tracker.id.replace(`${functionName}_`, '')] = tracker;
}

// Append the `fnTrackers` object to the parameterArray, to allow it to be
// accessed as the final argument in the callback, useful in environments that don't support `this` (GTM)
Array.prototype.push.call(parameterArray, fnTrackers);

input.apply(fnTrackers, parameterArray);
// Create a new array with the `fnTrackers` object as the last element, to allow it to be
// accessed as in the callback as the final argument, useful in environments that don't support `this` (GTM)
input.apply(fnTrackers, Array.prototype.concat.call(parameterArray, [fnTrackers]));
} catch (ex) {
LOG.error('Tracker callback failed', ex);
} finally {
Expand Down

0 comments on commit 7e3f9af

Please sign in to comment.