美文网首页
prototype 和 ——proto—— 使用不同的场景

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

作者: 小李不小 | 来源:发表于2020-09-08 10:16 被阅读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

相关文章

网友评论

      本文标题:prototype 和 ——proto—— 使用不同的场景

      本文链接:https://www.haomeiwen.com/subject/ejjcektx.html