构造函数原型对象prototype

 

 用法

 

class Star{
                constructor(name,age){
                    this.name=name;
                    this.age=age;
                }
            }
            Star.prototype.sing=function(){
                console.log(this.name+'会唱歌')
            }
            var ldh=new Star("刘德华",20)
            console.log(ldh)
            ldh.sing()

 

posted @ 2022-12-29 13:38  小闫的姑娘  阅读(12)  评论(0编辑  收藏  举报