← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

ES6 Class Syntax

JavaScript ES2015 Intermediate
debt(d5/e3/b3/t7)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). The detection_hints list ESLint and TypeScript as the tools. ESLint with appropriate rules can catch missing super() calls and temporal dead zone issues, but these aren't default linter catches — they require configured rules or TypeScript's stricter checking. The _ prefix for 'private' vs # private fields is a pattern-level issue a specialist tool would flag, not a compiler error.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix is clear and bounded: call super() before any this access in subclass constructors, and replace _ convention with # for truly private fields. These are targeted replacements within one component/file, not a cross-cutting refactor, but slightly more than a single-line patch since multiple constructors across a component may need updating.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). The applies_to scope is web and cli (broad JS contexts), but class syntax misuse tends to be contained within the class hierarchy itself. It doesn't reshape the entire codebase architecture; it imposes a tax on the component using inheritance, with limited propagation to consumers of the class.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception explicitly states that JS classes look like PHP classes but have fundamentally different semantics — prototypal inheritance, truly private # fields not accessible via reflection, and no interface keyword. This directly contradicts expectations from class-based OOP languages (PHP, Java, C#), making the 'obvious' mental model consistently wrong in ways that produce subtle runtime bugs.

About DEBT scoring →

Also Known As

ES6 class JavaScript class class syntax JS extends JavaScript

TL;DR

ES6 classes are syntactic sugar over prototypal inheritance — the keywords mirror PHP but the underlying mechanism is different.

Explanation

class, extends, super, static, constructor, get, set — familiar PHP-like syntax. Key differences: JavaScript classes are hoisted but not initialised (unlike PHP), private fields use # prefix (not access modifiers), static fields on the class not the prototype, and methods are non-enumerable. Class fields (public/private) are Stage 3+. No interfaces; use TypeScript or duck typing. super() must be called before using this in a subclass constructor.

Common Misconception

JavaScript classes work the same as PHP classes — JS classes are syntactic sugar over prototypes; private # fields are truly private (not accessible via reflection unlike PHP), and there is no interface keyword.

Why It Matters

PHP developers adopting JavaScript expect class-based OOP but prototypal inheritance has different semantics — understanding the differences prevents subtle bugs.

Common Mistakes

  • Forgetting super() in subclass constructor before using this
  • Using class before its declaration (temporal dead zone)
  • Expecting private fields accessible via Object.keys or JSON.stringify

Code Examples

✗ Vulnerable
class Animal {
    name; // public field
    constructor(name) { this.name = name; }
}

class Dog extends Animal {
    constructor(name) {
        this.bark(); // ReferenceError: must call super() first
        super(name);
    }
}
✓ Fixed
class Animal {
    #name;  // Truly private
    constructor(name) { this.#name = name; }
    get name() { return this.#name; }
    toString() { return this.#name; }
}

class Dog extends Animal {
    #breed;
    constructor(name, breed) {
        super(name); // super() first
        this.#breed = breed;
    }
    static create(name, breed) { return new Dog(name, breed); }
}

Added 17 Mar 2026
Edited 22 Mar 2026
Views 128
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 1 ping S 0 pings M 1 ping T 1 ping W 0 pings T 0 pings F 0 pings S 2 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 5 pings S 0 pings S 1 ping M 0 pings T 1 ping W 0 pings T 1 ping F 0 pings S
No pings yet today
PetalBot 1
Amazonbot 14 Scrapy 11 SEMrush 9 PetalBot 9 Ahrefs 8 Bing 7 Google 6 ChatGPT 6 Perplexity 5 Unknown AI 5 Claude 2 Twitter/X 2 Brave Search 2 Applebot 2 Majestic 1 Meta AI 1
crawler 83 crawler_json 4 your_contextpost 1 pre-tracking 2
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
JavaScript javascript The programming language of the browser — it reads and modifies the page (the DOM), reacts to user events, and fetches data without reloading.

JavaScript is the only language browsers execute, so every interactive behaviour on the web goes through it. Its two defining traits — single-threaded event loop and loose typing (== coercion) — explain the majority of both its bugs and its design patterns.

💡 Default to const, use === always, and reach for let only when a value genuinely reassigns.

Ask Codex about JavaScript →
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
Call super() before any this access in subclass constructors; use # for truly private fields not underscore convention
📦 Applies To
javascript ES2015 web cli
🔗 Prerequisites
🔍 Detection Hints
super() called after this in subclass constructor; _ prefix for 'private' instead of # private fields
Auto-detectable: ✓ Yes eslint typescript
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Medium Context: Class Tests: Update


✓ schema.org compliant