To determine whether the target reference contains a member with a null value, you'll have to write your own function as none exist out of the box to do this for you. One simple approach would be:
function hasNull(target) {
for (var member in target) {
if (target[member] == null)
return true;
}
return false;
}
Needless to say, this only goes one level deep, so if one of the members on target
contains another object with a null value, this will still return false. As an exmaple of usage:
var o = { a: 'a', b: false, c: null };
document.write('Contains null: ' + hasNull(o));
Will print out:
Contains null: true
In contrast, the following will print out false
:
var o = { a: 'a', b: false, c: {} };
document.write('Contains null: ' + hasNull(o));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…