Why does the following returns undefined?
var global_vars =
{
countNumOfProperties :
function (obj)
{
var count = 0;
for (var k in obj) {
if (obj.hasOwnProperty(k)) {
++count;
}
return count;
}
}
};
var DS =
{
file_types_lookup : {}
};
global_vars.countNumOfProperties(DS.file_types_lookup)
The
returnstatement is inside the loop so is never reached.should probably be
That way, each property will be checked before the sum is returned.
As written, the function will return
1to indicate that the first enumerable property is an own property, or0to indicate that there are no own properties but there are enumerable inherited properties, orundefinedto indicate that there are no enumerable propertiesownor otherwise.