hasOwnProperty验证对象属性是属于自身而不是从原型链上继承的

hasOwnProperty验证对象属性是属于自身而不是从原型链上继承的;

如:

  const p = {

    name: 'sky',

    age: 22,

  };

  p.hasOwnProperty('name'); // true

  p.hasOwnProperty('constructor'); // false, 这个属性是在原型链上的;

posted @ 2021-07-07 09:09  sky-su  阅读(105)  评论(0)    收藏  举报