class Point2{
constructor(name , age) { //只要触发new实例化操作即执行
this.name = name;
this.age = age;
} //注意在class类中,方法之间不需要添加逗号
showName(){
return `我的名字:${this.name}`;
}
showAge(){
return `我的年龄:${this.age}`;
}
}
var p2 = new Point2('测试2' , 20);
console.log(p2.showName(),p2.showAge());
const Point3 = class{
constructor(name , age) { //只要触发new实例化操作即执行
this.name = name;
this.age = age;
} //注意在class类中,方法之间不需要添加逗号
showName(){
return `我的名字:${this.name}`;
}
showAge(){
return `我的年龄:${this.age}`;
}
}
var p3 = new Point3('测试3' , 30);
console.log(p3.showName(),p3.showAge());