freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #39 of 61

classes · the ES6 syntax

LambdaVSThe Mutator
Lambda saysclass is syntax for creating objects with shared methods — a cleaner face on prototypes.

class User { … } defines a blueprint; new User() makes instances. Under the hood it's still prototypes, but the syntax is far clearer. Classes are not hoisted (use before define throws) and run in strict mode. They're the standard way to model entities with shared behavior.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleDefine a class with a method and create two instances.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>class Dog{ bark(){ return 'woof'; } }
const d=new Dog();
document.getElementById('o').textContent=d.bark();</script></body></html>
▶ Open the interactive comic issue
‹ Errors · Stack TracesClasses · Constructor · Methods · Getters ›