首页 > 其他分享 >构造函数原型对象prototype

构造函数原型对象prototype

时间:2022-12-29 13:44:41浏览次数:31  
标签:Star name age ldh 原型 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()

 

标签:Star,name,age,ldh,原型,prototype,构造函数
From: https://www.cnblogs.com/hs20011205/p/17010066.html

相关文章