javascript functions and arguments object, is there a cost involved

后端 未结 4 1758
北恋
北恋 2020-12-25 14:24

It is common place to see code like that around the web and in frameworks:

var args = Array.prototype.slice.call(arguments);

In doing so, you

4条回答
  •  無奈伤痛
    2020-12-25 14:47

    Here's some q&d testing. Using predefined arguments seems to be the fastest, but it's not always feasible to do this. If the arity of the function is unknown beforehand (so, if a function can or must receive a variable amount of arguments), I think calling Array.prototype.slice once would be the most efficient way, because in that case the performance loss of using the arguments object is the most minimal.

提交回复
热议问题