ES6 class syntax is often called "syntactic sugar" over prototypes — but what does that actually mean? This article desugars every class feature (constructor, methods, getters/setters, static, extends, super, private fields) into plain ES5 prototype code.
Prerequisites: JS Foundations #4 — Prototypes
1. Basic Class → Constructor + Prototype
Loading editor...
Key differences between class and a plain function + prototype:
class | function | |
|---|---|---|
Called without new | TypeError | Works (but likely wrong) |
| Methods enumerable? | No | Yes (by default) |
| Body strict mode? | Always strict | Only with "use strict" |
| Hoisted? | No (TDZ) | Function declarations: yes |
super available? | Yes | No |
arguments in methods? | No (use rest params) | Yes |
These differences are why class isn't just syntax sugar — it enforces better practices.
2. Getters and Setters
Loading editor...
3. Static Methods
Loading editor...
4. extends and super — The Full Desugar
Loading editor...
5. Private Fields — # Syntax
Private fields use WeakMap under the hood in transpilation:
Loading editor...
6. Full Checklist — What Desugars to What
Loading editor...
Key Takeaways
classis a function —typeof MyClass === "function".- All methods go on
ClassName.prototype— identical to ES5. extendssets upChild.prototype = Object.create(Parent.prototype).super()isParent.call(this, ...)in the constructor;super.method()isParent.prototype.method.call(this).- Private fields (
#x) transpile toWeakMap-based encapsulation. - Static members attach to the constructor function itself, not the prototype.
Next: V8 #3 — Deoptimization Patterns — what specific code patterns cause TurboFan to bail out.
