Javascript add extra argument

后端 未结 11 1196
暖寄归人
暖寄归人 2021-02-06 22:02

Lets take a look at this code:

var mainFunction = function() {
  altFunction.apply(null, arguments);
}

The arguments that are passed to \"mainF

11条回答
  •  轮回少年
    2021-02-06 22:19

    The arguments "array" isn't an array (it's a design bug in JavaScript, according to Crockford), so you can't do that. You can turn it into an array, though:

    var mainFunction = function() {
      var mainArguments = Array.prototype.slice.call(arguments);
      mainArguments.push('extra data');
    
      altFunction.apply(null, mainArguments);
    }
    

提交回复
热议问题