什么版本的javascript引入任意构造函数返回? [英] What version of javascript introduced arbitrary constructor return?
问题描述
问题中的某人有没有任何理由在构造函数中手动返回提到他认为在构造函数调用中返回任意对象可能已经在最新版本的Javascript中引入。
我现在无法访问备用浏览器,我找不到任何有关此信息,那么什么版本介绍了这个版本,或者它从来就存在了吗?
如果你看看< a href =http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%201st%20edition,%20June%201997.pdf =nofollow> ECMA- 262 ed 1 (仍可从ECMA网站在线获取),您将看到:
生产 NewExpression:new NewExpression 的计算方式如下:
- 评估NewExpression。
- 调用GetValue(Result(1))。
- 如果Result(2)未实现内部[[Construct]]方法,则会生成运行时错误。调用Result(2)上的[[Construct]]方法,不提供任何参数(即空参数列表)。
- 如果Type(Result(5) ,会产生运行时错误。
- 返回结果(5)。
$ b b
然后在§15.3.2.1#18中解释 因此,默认返回 Someone in the question Is there any reason to manually return in a constructor function mentioned that he thought that returning arbitrary objects in constructor calls may have been introduced in a recent version of Javascript. I am unable to access alternate browsers right now, and I can't find any information about this, so what version introduced this, or has it existed since forever? If it hasn't been around for long, then what browser versions will support it? If you look in ECMA-262 ed 1 (which is still available online from the ECMA site) you will see: 11.2.2 The new operator The production NewExpression : new NewExpression is evaluated as follows:
And then in §15.3.2.1 #18 the So a constructor returning 这篇关于什么版本的javascript引入任意构造函数返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! [[Construct]]
方法(下面,F是一个新构造的Function对象) / p>
18。
将F的[[Construct]]属性设置为,当它被调用时,构造一个新对象,其[[Prototype]]属性等于
到[[Construct]]方法是
调用时的F.prototype的值(但是如果这个值不是一个对象,那么使用
的值Object.prototype),然后调用F作为一个函数(使用其
[[Call]]属性)与新对象作为此值和
赋给[[Construct]]方法的参数作为参数。如果调用[[Call]]方法的
结果是一个对象,那么该对象
将成为调用[[Construct]]方法的结果;
否则新对象将成为调用
[[Construct]]方法的结果。
this
的构造函数自ECMAScript开始就已经存在。
[[Construct]]
method is explained (in the following, F is a newly constructed Function object):
18.
Set the [[Construct]] property of F to a method that, when it is invoked, constructs a new object whose [[Prototype]] property is equal
to the value of F.prototype at the time the [[Construct]] method is
invoked (but if this value is not an object then the value of
Object.prototype is used), then invokes F as a function (using its
[[Call]] property) with the new object as the this value and the
arguments given to the [[Construct]] method as the arguments. If the
result of invoking the [[Call]] method is an object, that object
becomes the result of the invocation of the [[Construct]] method;
otherwise the new object becomes the result of the invocation of the
[[Construct]] method.this
by default has been in ECMAScript since the beginning.