The following JavaScript code is very confusing to me. Could anyone help me understand. Why does PersonY not have prototype property.
PersonX = function(){};
PersonY = new function(){};
alert(PersonX.prototype);
alert(PersonY.prototype);
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.
Places a reference to an anonymous function into
PersonX.PersonXpoints to a function.Places a reference to a newly constructed instance of an anonymous constructor function into
PersonY.PersonYpoints to an object.Regarding the prototype,
PersonYhas one. However, since there were no properties and methods attached to the constructor before nor after instantiation, it has a blank prototype*.You can actually check
PersonY‘s prototype by doingconsole.log(PersonY). You will see that it has a prototype property (I see it as__proto__in Chrome) which is “blank”. But it has 2 hidden properties,constructorwhich is the constructor function that made the object, and another__proto__which leads you to the next “chain link” which would be theObjectobject.*Not really blank since prototype is a chain. This prototype level may be blank, but the next higher prototype may have, or in this case, does have properties and methods.