Sometimes I see something like this which I quite don’t understand:
// ...
that.constructor = ...
//...
I though the constructor property was not supposed to be something to assign something to, but a property that returned that which the object was an instance of. I thought that .constructor was a property like .length for strings that returns data and is not perferable to be changed. Is this true?
When an ECMAScript function object is created, it is given a public prototype property that is a plain object, just in case the function is used as a constructor. The prototype object is given a public constructor property that is a reference to the function. Instances created from the constructor will inherit the prototype’s constructor property (unless it is shaddowed by a constructor property on the instance or higher up its prototype chain).
The constructor property may be re-assigned, usually because the original prototype object is replaced with some other object. The constructor property can be set to anything, therefore it is not seen as particularly useful.
In regard to the prototye property of host objects (if they have one at all), be aware that they can do whatever they like (including throwing errors if you try to set or even access them).