9
rated 0 times
[
14]
[
5]
/ answers: 1 / hits: 45250
/ 12 Years ago, thu, october 4, 2012, 12:00:00
Possible Duplicate:
How do I check if an object has a specific property in JavaScript?
I found the following snippet in Twitter's JavaScript files. Why do they need to call the hasOwnProperty
function to see dict
has the key
property? The for loop is running for each 'key' in 'dict' which means 'dict' has 'key'. Am I missing a point?
function forEach(dict, f) {
for (key in dict) {
if (dict.hasOwnProperty(key))
f(key, dict[key]);
}
}
More From » javascript