篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text POO en JS 1相关的知识,希望对你有一定的参考价值。
class Person{
constructor(name, age){
this.name = name;
this.age = age;
}
tellMyName() { return `I am ${this.name}`}
tellMyAge() { return `I am ${this.age}`}
}
const john = new Person ("John", 40);
const mary = new Person ("Mary", 35);
console.log(john.tellMyName() + " and " + john.tellMyAge());
console.log(mary.tellMyName() + " and " + mary.tellMyAge());