How to understand if (name in {}) in javascript?
- by tiplip
I encounter a js function snippet, list as follows
each = function(obj, fun) {
if (typeof fun != "function") {
return obj
}
if (obj) {
var return_value;
if (obj.length === undefined) {
for (var name in obj) {
if (name in {}) { // how to undertand this line, what's purpose?
continue
}
return_value = fun.call(obj[name], obj[name], name);
if (return_value == "break") {
break
}
}
} else {
for (var i = 0,
length = obj.length; i < length; i++) {
return_value = fun.call(obj[i], obj[i], i);
if (return_value == "break") {
break
}
}
}
}
return obj
};
Thanks for your answer:)