JavaScript
Use this skill for JavaScript implementation, refactoring, debugging, or review when you need strong Java-style OOP conventions, ES2025+ standard features, t...
Documentation & Preview
Accessors
- Hide mutable state behind
#privatefields when encapsulation removes boilerplate. - Prefer intent methods over generic getters and setters.
- Avoid trivial getter/setter pairs that only mirror storage.
- Use accessors for computed, side-effect-free views.
- Keep validation and invariants inside the type.
Example
class InvoiceDraft {
#status = "NEW";
markSubmitted() {
if (this.#status !== "NEW") {
throw new Error("Only new drafts can be submitted");
}
this.#status = "SUBMITTED";
}
get isSubmitted() {
return this.#status === "SUBMITTED";
}
}End Check
- Verify callers cannot bypass invariants.
- Verify accessors expose views, not hidden mutations.
- Verify behavior methods replace trivial property mutation APIs.