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
  • 26,331
  • 9
  • 49
  • 67
Titulum
  • 9,928
  • 11
  • 41
  • 79
  • 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
  • 99,490
  • 19
  • 131
  • 169