版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/q95548854/article/details/79083932
六、Class的基本运用
Class面向对象 与 构造函数法面向对象
//构造函数
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype = {
constructor: Person,
print(){
console.log('我叫' + this.name + ',今年' + this.age + '岁');
}
};
//Class面向对象
class Person{
constructor(name, age){
this.name = name;
this.age = age;
};
print(){
console.log('我叫' + this.name + ',今年' + this.age + '岁');
}
}