If I do this:
for (var i in obj) {
if (obj.hasOwnProperty(i)) console.log("Has property: " + i);
else console.log("Doesn't have property: " + i);
}
Will obj.hasOwnProperty(i) ever return false? If so, when?
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.
The idea of using hasOwnProperty within a loop is to resolve to false when looping over inherited properties. This avoids what Douglas Crockford refers to as a “deep-dredge.”
Example from https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/hasOwnProperty :