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

首先说一下,
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 instanceof Function //true
 Object instanceof Object
 
   Function.__proto__ == Function.prototype //true
   Object.__proto__ == Function.prototype //true
 
   Function.isPrototypeOf(Object) //false
   Function.prototype.isPrototypeOf(Function)  // true
   Function.prototype.isPrototypeOf(Object)  //true
 Object.prototype.isPrototypeOf(Function) //true
 Object.prototype.isPrototypeOf(Object)   //true
  </script>

  <script> 

 

posted @   国服第一李师师  阅读(272)  评论(1编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示