Javascript:参数数组是否已弃用?
大多数网站都说 callee
作为 Function.arguments
的属性已被弃用。但有些网站更进一步,说整个 Functions.argument
已被弃用,例如 https://web.archive.org/web/20130313045745/http://aptana.com/reference/api/Arguments.html 。如果整个例程都死了,为什么只提到被调用者呢?我刚刚发现了arguments
,它似乎非常有用,例如:http://hungred.com/how-to/secret-arguments-array-javascript/
Most sites say callee
as a property of Function.arguments
is deprecated. But some sites go further and say the whole of Functions.argument
is deprecated E.g. https://web.archive.org/web/20130313045745/http://aptana.com/reference/api/Arguments.html . Why only mention callee if the whole routine is dead in the water? I only just discovered arguments
and it seems incredibly useful E.g: http://hungred.com/how-to/secret-arguments-array-javascript/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Function.arguments
已已弃用,但它只是被弃用,以支持函数中可用的普通arguments
对象。 (例如使用x = argument[i];
而不是x = theFunc.arguments[i];
)这是现在首选的(正如你所说的,非常有用)方法用于访问收到的序数参数。
Function.arguments
is deprecated, but it's only deprecated in favor of the vanillaarguments
object that's available within a function. (e.g. usingx = arguments[i];
instead ofx = theFunc.arguments[i];
)That's now the preferred (and as you say, extremely useful) method for accessing the ordinal arguments received.
Afaik
arguments
作为 Function 的属性已被弃用。。请参阅此 MDN 链接,或这个Afaik
arguments
is deprecated as a property of Function. See this MDN-link, or this oneJavascript “参数数组” — 不是已弃用,但我想说截至 2021 年已过时:
以下是显示首选实践的示例:
上面的引用和代码示例来自标题为 JavaScript 参数和参数
The Javascript "argument array" — not deprecated, but I would say outdated as of 2021:
Here is an example showing preferred practice:
The above quote and code sample are from an article titled JavaScript Parameters and Arguments
callee 已被弃用,但参数在许多应用程序中使用。我不知道参数是否已被弃用。您可以使用它来获取函数的所有参数,即使函数中没有定义( params )。
大多数时候我在开发 jQuery 插件时使用。类似于:
如您所见,只有方法作为参数传递,但如果参数在第一个值之后拆分,则在第一个参数中传递。这样您就可以传递函数名称以及该函数使用的所有参数。
完整示例: http://docs.jquery.com/Plugins/Authoring
callee is deprecated, but the arguments is used in many applications. I don't know if arguments is deprecated. You can use it to get all the parameters of a function, even if there not defined within function( params ).
Most of the time I used when I develop a jQuery plugin. Something like:
As you can see only method is passed as a parameter, but within the first if the arguments is split after the first value. This way you can pass a function name, and all parameters used by this function.
Full example: http://docs.jquery.com/Plugins/Authoring
不,参数数组在最新的 5.1 版规范中并未被弃用(请参见第 60 页)。然而,只有当代码不处于严格模式时,
caller
对象才可用。No, the arguments array is not deprecated in the latest 5.1 version of the specification (see page 60). The
caller
object will however only be available if the code is not in strict mode.