I don't understand what's wrong with JS. I thinked that properties
property always return all properties, but in my case it's undefined!
I simply want a method returning null when all object's properties are undefined. Here is my realisation
function nullifyUndefined(obj) {
debugger;
for (var property in obj.properties) {
if (obj.properties.hasOwnProperty(property) && typeof obj.properties[property] != 'undefined') {
return obj;
}
}
return null; // all properties are null, trait it as null object
}
But it doesn't work, simply becuase obj.properties
is undefined. Here is a screenshot:
Why? And how to fix it?
Aucun commentaire:
Enregistrer un commentaire