class Star {
constructor(uname, age) {
this.uname=uname;
this.age = age;
}
sing(song){
console.log(`${this.uname}的${song}`);
}
}
var ldh = new Star("刘德华", 60);
var zxy = new Star("张学友", 50);
console.log(zxy);
console.log(ldh);
ldh.sing("我爱你")
zxy.sing("哈哈哈")
1.类里面所有函数不需要写function
2.多个函数方法之间不需要添加逗号分隔符
网友评论