var myProp = 'prop';if(myObj.hasOwnProperty(myProp)){ alert("yes, i have that property");}要么
var myProp = 'prop';if(myProp in myObj){ alert("yes, i have that property");}要么
if('prop' in myObj){ alert("yes, i have that property");}请注意,
hasOwnProperty它不会检查继承的属性,而
in会。例如,
'constructor' inmyObj是正确的,但事实
myObj.hasOwnProperty('constructor')并非如此。


