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:
undefined
?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).
A slightly simpler way than your method is to use the Javascript in operator
alert('x' in o); // true
alert('x' in t); // false