大多数网站都说“被调用者”作为 Function.arguments 的属性已被弃用。但是有些网站走得更远,说整个 Functions.argument 已被弃用 例如http://aptana.com/reference/api/Arguments.html如果整个例程都死在水中,为什么只提到被调用者?我刚刚发现“参数”,它似乎非常有用例如:http ://hungred.com/how-to/secret-arguments-array-javascript/
问问题
6746 次
4 回答
48
Function.arguments
已弃用,但仅弃用它以支持arguments
函数中可用的 vanilla 对象。(例如使用x = arguments[i];
代替x = theFunc.arguments[i];
)
现在,这是访问收到的序数参数的首选方法(正如您所说,非常有用)。
于 2011-11-14T12:06:04.147 回答
1
callee 已被弃用,但参数在许多应用程序中使用。我不知道参数是否已被弃用。您可以使用它来获取函数的所有参数,即使没有在函数(参数)中定义。
大多数时候我在开发 jQuery 插件时使用。就像是:
$.fn.tooltip = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
}
};
如您所见,只有方法作为参数传递,但如果参数在第一个值之后拆分,则在第一个值内。这样你就可以传递一个函数名,以及这个函数使用的所有参数。
于 2011-11-14T12:06:48.670 回答
1
不,参数数组在最新的 5.1 版规范中没有被弃用(参见第 60 页)。但是,该caller
对象仅在代码未处于严格模式时才可用。
于 2011-11-14T12:07:02.043 回答