有关自有属性,原型属性的问题

首先说一下,
Object.create()创造出来的

Object.create({pname:'plishishi'},{
name:{
  value:'lishishi'
}
})

现在看到的第一个参数里面的对象就是__proto__里面的属性

除了这种写法还可以写成Object.create(Object.prototype,{
name:{
  value:'lishishi'
}
})
下面再说下for in,for in 是只能遍历可枚举的

再讲下Object.keys(),只能遍历自有属性,并且是可枚举属性.

Object.hasOwnProperty('panme') ,能查找自有属性里面有没有

'pname' in obj2 //true  in不能查找自有属性里有没有

Object.getOwnPropertyDescriptors(obj2),这个方法是查看自有属性里面的东西

Object.property.toString.call()  //这里面的对象可以具体查看到他是数组还是什么别的东西

//后面是2020/10/15补起来

<script>
    const obj1 = {pname:'lishishi'}
    const obj2 = Object.create(obj1,{  //默认也是false
      name:{
        value:'baimingyu',
        // configurable:true,
        //enumerable:true, 
      },
      sex:{
        value:'男'
      }
    })

    ///get,set叫访问器属性[configurable,enumerable,get,set]
    Object.defineProperty(obj2,'hobby',{  //默认为false
      value:'play',
      //configurable:true,//能删除
      //writable:true,//能改
    })
    obj2.hobby = 'study'
    console.log(obj2.hasOwnProperty('pname'))  //没有原型
    console.log(Object.getOwnPropertyDescriptors(obj2))
    console.log('pname' in obj2)
    console.log(Object.getOwnPropertyDescriptors(obj2.__proto__))
    for(let p in obj2){  //可枚举的,原型上的
      console.log(p)
    }
    console.log(Object.keys(obj2))   //自身属性,可枚举的  configurable可编辑的,enumerable可枚举的
    console.log(Object.getPrototypeOf(obj2))
 Function instanceof Object //true
    Object instanceof Function // true
    Function.__proto__ == Function.prototype //true
    Object.__proto__ == Function.prototype //true
    Function.isPrototypeOf(Object) //false
   Function.prototype.isPrototypeOf(Function)  // true
    Function.prototype.isPrototypeOf(Object)  //true
  </script>

  <script> 
原文地址:https://www.cnblogs.com/MDGE/p/11668390.html