The first case is not an error because if a constructor returns a non-primitive value, it is returned instead of the object created. Therefore, simplified, following happens:
- A new object is created
- The new object’s internal
__proto__
variable is set toFoo.specialConstructor.prototype
Foo.specialConstructor
is executed using the created object as a this variable- Because
Foo.specialConstructor
returns a non-primitive value, it is returned by the new operator instead of the newly created object
The second case is an error because the new operator can only be used on functions.
solved Why is it valid to call new again here?