class User {
constructor(name) {
this.name = name;
}
sayHi() {
alert(this.name);
}
}
// Usage:
let user = new User("John");
user.sayHi();
In practice, we often need to create many objects of the same kind, like users, or goods or whatever.
As we already know from the chapter Constructor, operator "new", new function can help with that.
But in the modern JavaScript, there’s a more advanced “class” construct, that introduces great new features which
are useful for object-oriented programming.
class MyClass {
// class methods
constructor() { ... }
method1() { ... }
method2() { ... }
method3() { ... }
...
}
Get Skeleton CSS Fun and Games
Anchor button Anchor buttonFriday November 12 2021 0720 AM