- 如何在构造方法中创建函数(方法)?
class User {
constructor(name) {
this.name = name;
sayHi() {
alert('hello');
}
}
}
// Использование:
let user = new User("Иван");
user.sayHi();
class User {
constructor(name) {
this.name = name;
sayHi() {
alert('hello');
}
}
}
// Использование:
let user = new User("Иван");
user.sayHi();
2 个回答