对象:
var testDemo=new TestDemo();
判断对象testDemo是否拥有指定的name属性
1)使用in关键字
console.log('name' in testDemo);
使用这个方法不仅检查到自有属性,并且同时检查当前对象原型共有属性
2)使用对象的hasOwnProperty()方法
console.log(testDemo.hasOwnProperty('name'));
3)使用undefined判断
console.log(testDemo.name===undefined);
4)在条件语句中直接判断
if(testDemo.name){
console.log("name属性存在");
}else{
console.log("name属性不存在");
}