prototype 和 ——proto—— 使用不同的场景

2020-09-08  本文已影响0人  小李不小

——proto—— 使用于使用函数和对象方法

let hd={
        'name':'123',
    }

        hd.__proto__.show=function(){
        console.log('show2')
    }
console.log(hd)
    hd.show()

image.png

prototype 使用于 实列化函数方法

    
 function   hd(){
 } 

        hd.prototype.show=function(){
        console.log('show2')
    }

    const hfnew=new  hd();

console.log(hfnew)
hfnew.show()
image.png
上一篇 下一篇

猜你喜欢

热点阅读