Consider the following snippet:
f = function() {};
f.prototype = {};
thing = new f;
I was surprised to see that thing.constructor is Object(). (See fiddle here.)
Why isn’t thing.constructor the function f?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because you’ve entirely replaced the original
prototypeobject offwith a plain object. It was the originalprototypeobject that held the reference tofvia the.constructorproperty.The constructor of an object created using object literal syntax will be the
Objectconstructor.To get it back, you’d need to put it there manually.
This will shadow the
.constructorproperty on in the prototype chain of the new prototype object.If you delete that property, you’ll get
Objectagain.