基础版 let hasPubProperty = function hasPubProperty(obj,attr){ return (attr in obj) && obj.hasOwnProperty(attr); } 完美版 Object.prototype.hasPubProperty = function hasPubProperty(attr){ let self = this; let protoType = Object.getPrototypeOf(self); while(protoType){ if(protoType.hasOwnProperty(attr))return true; protoType = Object.getPrototypeOf(protoType); } return false; } 完美简化版 Object.prototype.hasPubProperty = function hasPubProperty(attr){ let protoType = Object.getPrototypeOf(self); //in操作符检测的特点:先看自己私有中是否有,如果没有会默认按原型链一层层查找 return attr in protoType; }