class Class
Last updated: 2026-09-09
class Class
class is a template for creating objects with a constructor, methods and getters/setters.
| Category | Statements |
|---|---|
| ES version | ES2015 |
📝 Syntax
class Name {
constructor(p) { this.x = p; }
method() { ... }
}
Returns:The constructor (requires new).
Mutates the original:No (returns a new value)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
Hello, Zhang
Zhang (25)
💡 Tip class is syntactic sugar for prototype inheritance.
ℹ️ info extends for inheritance; super() calls the parent constructor.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| class | ✓ v32 | ✓ v12 | ✓ v27 | ✓ v8 | ✓ v19 |
| Supported by all modern browsers | |||||
🏷️ Related Items
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
Qclass vs function for objects?
Aclass is clearer: constructor, methods on prototype, requires new, strict mode by default.
QDo class methods need commas?
ANo — class methods have no commas.
QWhat is extends?
AClass inheritance — the child inherits from the parent.