- Is there any possibility of
anyObject.constructorproperty being null or undefined(especially when ConstructorFunc.prototype is not modified/overwritten)? var date = new Date(); console.log(date.constructor);// logs “Date()”. ok, fine.
var data = new Array(1, 2, 3); console.log(data.constructor);// it logs something like [ undefined ]. What is it and why is not Array().
TIA
Yes, you can manually overwrite the
.constructorproperty of a constructor function’sprototypeobject.It seems that the
constructorproperty has been changed. Normally you’d probably see something likefunction Array() { [native code] }instead of[ undefined ].One thing you can do to verify is…
It should give you
"function". If it gives you"object", then it’s been changed.Don’t trust console output
It seems from a comment that you’re testing in Firebug.
As a general rule do not put too much trust in console logging. Consoles are addons to the environment, and must interpret what they’ve been given to log. Sometimes the interpretation is misleading.
If you get odd results, then perform other tests…
So you can see that even though Firebug gave an odd interpretation of the function itself, it doesn’t change the fact that it is still the expected
Arrayconstructor.