判断属性是否存在于实例对象和原型对象中

// 判断属性是否存在于实例对象中 for-in


function Person(name, age) {
    this.name = name;
    this.age = 20;
}
var p = new Person();

console.log('name' in p) //true

//判断一个属性是否存在原型中

function hasPrototypeProper(object, name) {
    return !object.hasOwnProperty(name) && name in object;
}
原文地址:https://www.cnblogs.com/goweb/p/5650880.html