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
  • 22,934
  • 9
  • 44
  • 60
Titulum
  • 7,325
  • 6
  • 37
  • 63
  • 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
  • 95,368
  • 17
  • 122
  • 158