Say I have the following code:
function One() {}
One.prototype.x = undefined;
function Two() {}
var o = new One();
var t = new Two();
o.x
and t.x
will both evaluate to undefined
. o.hasOwnProperty('x')
and t.hasOwnProperty('x')
will both return false; the same goes for propertyIsEnumerable
. Two questions:
- Is there any way to tell that o.x is defined and set to
undefined
?
- Is there ever any reason to? (should the two be semantically equivalent?)
A small caveat: doing (for propName in o) loop will yield 'x' as one of the strings, while doing it in t will not - so there IS a difference in how they're represented internally (at least in Chrome).
question from:
https://stackoverflow.com/questions/385960/javascript-identify-whether-a-property-is-defined-and-set-to-undefined-or-u 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…