Search code examples
javascriptinternet-explorer-11ecmascript-5

Pass arguments to function without spread (IE11)


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.


Solution

  • Like this:

    function log(level, message) {
      console.log(level + " " + message);
    }
    
    function supplyToLogger() {
      log.apply(null, arguments);
    }
    
    supplyToLogger("WARN", "This is a warning.");