If I have a javascript class which cannot be instantiated what should the constructor return that I can test for. The constructor always returns an object so I cannot return nul
Returning any non-object from the constructor is practically the same as exiting the constructor. (The constructor will return a new object, with a prototype
if one was specified.)
So, returning null
, undefined
, or 42
from the constructor are equivalent.
Check out section 13.2.2 of the ECMAScript spec (pdf) for more info.