Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a constructor always a function object?

Tags:

javascript

I'm reading the latest ECMA-262 reference, edition 5.1 June 2011.

In section 8.6.2 table 9 we have in regard to the [[Construct]] internal property:

Creates an object. Invoked via the new operator. The arguments to the SpecOp are the arguments passed to the new operator. Objects that implement this internal method are called constructors.

The standard doesn't say that a constructor has to be a Function object. So can we have a constructor object that is not a function object?

Link to the standard as requested

like image 242
Roland Avatar asked May 01 '12 05:05

Roland


1 Answers

The answer is extremely simple. ES5 § 4.3.4 says:

Constructor Function object that creates and initialises objects.

So there you have it, by definition only a Function can be a constructor. However, likely there are host objects that behave like constructors that do not have any of the other attributes of native Function objects (e.g. the original XMLHttpRequest object in IE that was implemented in ActiveX).

like image 179
RobG Avatar answered Sep 17 '22 17:09

RobG