Skip to content

Instantly share code, notes, and snippets.

@hinell
Created July 20, 2020 20:56
Show Gist options
  • Save hinell/3148837767e41d2181718ebbfca1990f to your computer and use it in GitHub Desktop.
Save hinell/3148837767e41d2181718ebbfca1990f to your computer and use it in GitHub Desktop.
Maximum number of items that can be safely passed into .apply(...) invocation
// Description: The code below fails in two major browsers due to exceeding number
// of argumnets that can be safely passed into `.apply(...)`
// invocation of the `test(...)` function.
(function(){
console.clear();
upperBound = {};
// Substruct 1 to let the magic happen
upperBound.Chrome = Math.pow(2, 16) + 55155;
upperBound.Firefx = Math.pow(2, 18) + 237857;
let size = navigator.product === "Gecko"
? upperBound.Firefx
: upperBound.Chrome;
let args = new Array(size).fill(null);
let test = function(){};
test(...args); // fail
test.apply(null, args); // same, but for ...apply(...)
console.log(`Call is over!`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment