两种属性: 自身属性和 prototype 属性。 自身属性是直接在对象上定义的。 而原型属性在 prototype 上定义。
function Dog(name) {
this.name = name;
}
Dog.prototype.numLegs = 4;
let beagle = new Dog("Snoopy");
let ownProps = [];
let prototypeProps = [];
// 只修改这一行下面的代码
for(let property in beagle){
// console.log(property)包含原型上的属性
// console.log(beagle)
if(beagle.hasOwnProperty(property)){//自身的属性
ownProps.push(property)
}else{
prototypeProps.push(property)
}
}