What's the returned value of javascript constructor function
2014-11-19 23:38
435 查看
Example:
The exact condition is described on the
property, which is used by the
From the ECMA-262 3rd. Ediion Specification:
13.2.2
When the
for a
called, the following steps are taken:
Create a new native ECMAScript object.
Set the
of
Get the value of the prototype property of
If
an object, set the
of
If
not an object, set the
of
the original
object as described in 15.2.3.1.
Invoke the
of
providing
the
and providing the argument list passed into
the argument values.
If
return
Return
Look at the steps 7 and 8, the new object will returned only if the type of
value returned from the
function) is not an Object.
Steps 7 “Type(x) is Object” means “x instance of Object is true”, not “typeof(x) === ‘object’ is true”
Add one website for refer http://dmitrysoshnikov.com/ecmascript/javascript-the-core/
function Foo(){ return something; } var a = new Foo();
The exact condition is described on the
[[Construct]]internal
property, which is used by the
newoperator:
From the ECMA-262 3rd. Ediion Specification:
13.2.2
[[Construct]]
When the
[[Construct]]property
for a
Functionobject
Fis
called, the following steps are taken:
Create a new native ECMAScript object.
Set the
[[Class]]property
of
Result(1)to
"Object".
Get the value of the prototype property of
F.
If
Result(3)is
an object, set the
[[Prototype]]property
of
Result(1)to
Result(3).
If
Result(3)is
not an object, set the
[[Prototype]]property
of
Result(1)to
the original
Objectprototype
object as described in 15.2.3.1.
Invoke the
[[Call]]property
of
F,
providing
Result(1)as
the
thisvalue
and providing the argument list passed into
[[Construct]]as
the argument values.
If
Type(Result(6))is
Objectthen
return
Result(6).
Return
Result(1).
Look at the steps 7 and 8, the new object will returned only if the type of
Result(6)(the
value returned from the
Fconstructor
function) is not an Object.
Steps 7 “Type(x) is Object” means “x instance of Object is true”, not “typeof(x) === ‘object’ is true”
Add one website for refer http://dmitrysoshnikov.com/ecmascript/javascript-the-core/
相关文章推荐
- What the heck is "H5N1"?
- 'You've got to find what you love,' Jobs says
- What is the difference between angle bracket < > and double quotes " " while including header files
- C++ -> C#: What You Need to Know to Move from C++ to C#
- What's New in System.Xml for Visual Studio 2005 and the .NET Framework 2.0 Release
- What&#39;s Special About This Number?
- [原创]What is "Type" in managed heap?
- What's OO?
- [Quora] What is the most elegant line of code you've seen?
- What's new in PowerShell ISE
- What To Do and Not To Do When 'shutdown immediate' Hangs [ID 375935.1]
- Turning Off & editting "What's New Window" For virtuoso
- What is portal? & What is portlet?
- SharePoint 2016 的新特性概览(一)(What's New for IT Professionals in SharePoint Server 2016)
- DXperience 7.3.5 released on 13 Dec 2007 and What'a New
- What's the difference between headsets and headphones?
- What's SSL & TLS
- What’s the Difference Between Sudo & Su?
- What UML Is and Isn't
- what is "AOP"