指示函数使用'arguments'对象的最明确方法是什么? [英] What's the clearest way to indicate a function uses the 'arguments' object?
本文介绍了指示函数使用'arguments'对象的最明确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
表明函数使用'arguments'对象的最佳方法是什么?
这显然是基于意见的,但是有没有约定?什么时候使用一组参数更好?
What's the best way to indicate a function uses the 'arguments' object?
This is obviously opinion based but are there any conventions? When would it be better to use an array of arguments?
一些例子:
// Function takes n arguments and makes them pretty.
function manyArgs() {
for (var i = 0; i < arguments.length; i++)
console.log(arguments[i]);
}
function manyArgs( /* n1 , n2, ... */ )
function manyArgs(n1 /*, n2, ... */ )
function manyArgs(argArray)
推荐答案
// Using ES6 syntax ...
var foo = function(/*...args*/){
// shim Array.from, then
var args = Array.from(arguments);
// or
var args = [].slice.call(arguments);
};
这篇关于指示函数使用'arguments'对象的最明确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文