“参数” - 参数是否会覆盖“参数”对象? [英] does a "parameters"-parameter overwrite the "parameters"-object?

查看:86
本文介绍了“参数” - 参数是否会覆盖“参数”对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写JS-> Scheme编译器(使用Bigloo,

自动生成JS-> C,JS-> JVM,JS->。 NET编译器),并且有关于函数参数的

问题:

根据规范(10.1.6),激活对象已经包含了

变量实例化时的参数对象(10.1.3)。

问题现在是:参数"参数"是否覆盖了

" parameters" -object?

我测试过的所有三个实现(Konqueror,Mozilla和Rhino)都没有覆盖
覆盖对象,但我已经看到所有三个在其他简单的

示例中失败。

这是一个最小的例子:

= ==

函数g(参数){

alert(arguments.length);

}

g({长度:"对象"}); // => "对象" ;? 1?

===

// florian loitsch

I''m currently writing a JS->Scheme compiler (which, using Bigloo,
automatically yields a JS->C, JS->JVM, JS->.NET compiler), and have a
question concerning the function-parameters:
According to the spec (10.1.6) the activation-object already contains the
the parameters-object when the variables are instantiated (10.1.3). The
question is now: does a parameter "parameters" overwrite the
"parameters"-object or not?
All three implementations I tested (Konqueror, Mozilla and Rhino) do not
overwrite the object, but I''ve already seen all three fail on other simple
examples.
Here''s a minimal example:
===
function g(parameters) {
alert(arguments.length);
}
g({length:"object"}); // => "object"? 1?
===
// florian loitsch

推荐答案

Florian Loitsch写道:
Florian Loitsch wrote:
function g(parameters){
alert(arguments.length);
}
g({length:" object"}); // => "对象" ;? 1?
function g(parameters) {
alert(arguments.length);
}
g({length:"object"}); // => "object"? 1?




1.


在你的函数g中,参数或参数 [0]",

但不是参数会引用你提供的匿名对象作为第一个参数。


ciao,dhgm



1.

In your function "g", either "parameters", or "arguments[0]",
but not "arguments" would reference the anonymous object you
supplied as the first argument.

ciao, dhgm


当我写这个测试用例时,显然我累了...

替换所有参数用参数在我的帖子中。

- >问题变成:

===

函数g(参数){

alert(arguments.length);

}

g({length:" object"}); //对象?或者1?

===


在这种情况下Konqueror,Rhino以及Mozilla返回对象 (我希望它是b $ b期望它,尽管我不完全确定,如果它在

规范中定义)。

对不起输入错误...

// florian loitsch
Obviously I was tired when I wrote this test case...
replace all "parameters" with "arguments" in my post.
-> question becomes:
===
function g(arguments) {
alert(arguments.length);
}
g({length:"object"}); // "object"? or 1?
===

and in this case Konqueror, Rhino as well as Mozilla return "object" (what I
expect it to be, eventhough I''m not completely sure, if it is defined in
the spec).
sorry for the typo...
// florian loitsch


Florian Loitsch写道:


[snip]
Florian Loitsch wrote:

[snip]
===
函数g(参数){
alert(arguments.length);
}
g( {长度:"对象"}); //对象?或1?
===

在这种情况下Konqueror,Rhino以及Mozilla返回
object (我希望它是什么,尽管我不完全确定,如果在规范中定义的话)。
===
function g(arguments) {
alert(arguments.length);
}
g({length:"object"}); // "object"? or 1?
===

and in this case Konqueror, Rhino as well as Mozilla return
"object" (what I expect it to be, eventhough I''m not completely
sure, if it is defined in the spec).




规范意味着第10.1.6节中的顺序 - 激活对象:


"当控件进入功能代码的执行上下文时,会创建一个名为激活对象的
对象并与执行上下文关联

。激活对象初始化

,带有名称参数和属性的属性

{DontDelete}。此属性的初始值是下面描述的

参数对象。


激活对象随后用作
$ b的变量对象$ b变量实例化的目的。


激活对象初始化为arguments属性,

之后,相同的对象用于变量实例化。由于

arguments属性不具备ReadOnly属性,因此假设任何使用相同实例化的局部变量

是安全的。 name应该覆盖arguments对象。另请注意使用

短语初始值,这意味着arguments属性可以

取另一个值。


Mike


-

Michael Winter

替换.invalid与.uk通过电子邮件回复。



The specification implies the order in section 10.1.6 - Activation Object:

"When control enters an execution context for function code, an
object called the activation object is created and associated
with the execution context. The activation object is initialised
with a property with name arguments and attributes
{ DontDelete }. The initial value of this property is the
arguments object described below.

The activation object is then used as the variable object for
the purposes of variable instantiation."

The activation object is initialised with the arguments property,
after which the same object is used for variable instantiation. As the
arguments property does not possess the ReadOnly attribute, it is safe
to assume that any local variable that is instantiated with the same
name should overwrite the arguments object. Also notice the use of the
phrase "initial value", which implies that the arguments property can
take on another value.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.


这篇关于“参数” - 参数是否会覆盖“参数”对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆