.hasOwnProperty(propname)方法来确定该对象是否具有给定的属性名称。 .hasOwnProperty()如果找到属性则返回true或false 。 例 var myObj = {
顶部:“帽子”,
底部:“裤子”
};
myObj.hasOwnProperty( “顶部”); //真的
myObj.hasOwnProperty( “中间”); //假
checkObj以测试myObj的checkProp 。如果找到该属性,则返回该属性的值。如果没有,请返回"Not Found" 。 checkObj("gift")应该返回"pony" 。
testString: 'assert(checkObj("gift") === "pony", "checkObj("gift") should return "pony".");'
- text: checkObj("pet")应该返回"kitten" 。
testString: 'assert(checkObj("pet") === "kitten", "checkObj("pet") should return "kitten".");'
- text: checkObj("house")应该返回"Not Found" 。
testString: 'assert(checkObj("house") === "Not Found", "checkObj("house") should return "Not Found".");'
```