js如何判断属性是自己具备仍是继承别人的

function Person(name, age) {
    this.name = 'Tom';
    this.age = 11;
};
Person.prototype = {
    job:'资深前端开发工程师',
};

var p = new Person();

console.log(p.name);
console.log(p.age);
console.log(p.job);
console.log('name是对象p自身的属性吗?',Object.prototype.hasOwnProperty.call(p, 'name'));//true
console.log('age是对象p自身的属性吗?',Object.prototype.hasOwnProperty.call(p, 'age'));//true
console.log('job是对象p自身的属性吗?',Object.prototype.hasOwnProperty.call(p, 'job'));//false 复制代码
相关文章
相关标签/搜索