原型链深入理解、delete删除

  • 函数就是原型的构造函数
function Person(){//这个函数就是原型的构造函数

        }
        Person.prototype.name = 'malinshu'
        console.log(Person.prototype.constructor == Person)//true
        let person1 = new Person.prototype.constructor()
        console.log(person1.name)
  • instanceof
        let person = new Person()
        console.log(person instanceof Person)//true  person是Person的实例
  • 实例通过__proto__访问原型
        console.log(person.__proto__==Person.prototype)
        let person2 = new person.__proto__.constructor()
        console.log(person2.name)
  • 访问不到实例的属性时,就会找原型的属性
        console.log(person.name)//malinshu
        person.name = 'linshu'
        console.log(person.name)//linshu
        delete(person.name)
        console.log(person.name)//malinshu
  • 删除原型属性
        

        delete(Person.prototype.name)
        console.log(Person.prototype.name)//undefined
  • delete删除数组元素
        let arr = [1,2,3,4,5]
        delete arr[1]
        console.log(arr,arr.length)//[1, empty, 3, 4, 5] 5
        for(let i in arr){
            console.log(arr[i])//empty不会被打印
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值