0

Imagine I have the following code:

function log(level, message) {
  console.log(level + " " + message);
}

function supplyToLogger() {
  log(...arguments);
}

supplyToLogger("WARN", "This is a warning.");

How can I supply the arguments object to the log function without the spread operator? I need this to work in IE11, without the use of polyfills.

VLAZ
  • 18,437
  • 8
  • 35
  • 54
Titulum
  • 5,744
  • 3
  • 25
  • 52
  • 1
    Also relevant: [Is it possible to send a variable number of arguments to a JavaScript function?](https://stackoverflow.com/q/1959040) | [What is the difference between call and apply?](https://stackoverflow.com/q/1986896) | [Pass unknown number of arguments into javascript function](https://stackoverflow.com/q/4116608) – VLAZ Nov 27 '20 at 11:57

1 Answers1

1

Like this:

function log(level, message) {
  console.log(level + " " + message);
}

function supplyToLogger() {
  log.apply(null, arguments);
}

supplyToLogger("WARN", "This is a warning.");
JLRishe
  • 90,548
  • 14
  • 117
  • 150