javascript-modern
Acknowledgement: Shared by Peter Bamuhigire, techguypeter.com, +256 784 464178.
Use When
- Modern JavaScript (ES6+) patterns for PHP+JavaScript SaaS apps: modules, async/await, destructuring, Proxy/Reflect, generators, WeakMap/WeakSet, optional chaining, error handling, and performance patterns. Use when writing JavaScript for web...
Workflow
- For OOP-heavy browser modules, reusable UI widgets, or complex stateful workflows, pair with
references/javascript-patterns.md and load references/javascript-patterns.md.
- For Node/runtime container work, pair with
docker-development.
Evidence Produced
| Category |
Artifact |
Format |
Example |
| Correctness |
JavaScript module test plan |
Markdown doc covering async, generators, Proxy, and module boundary tests |
docs/web/js-module-tests.md |
References
- Use the
references/ directory for deep detail after reading the core workflow below.
- Use
references/javascript-advanced.md when the task needs deeper ES language mechanics, async patterns, metaprogramming, or performance.
- Use
references/javascript-patterns.md when the task involves OOP, prototypes, design patterns, event modules, or maintainable browser architecture.
Expert-level ES6+ patterns for PHP+JavaScript SaaS developers. Assumes fluency with variables, loops, and functions.
Architecture Rule (Non-Negotiable)
JavaScript belongs in its own .js files. PHP only emits a <script src="..."> tag or passes config via a single JSON data attribute. No <?php echo $var ?> scattered through JS files.
<!-- PHP emits one data attribute — no inline JS -->
<div id="app-config"
data-config='<?= json_encode($config, JSON_HEX_APOS) ?>'
data-user='<?= json_encode(['id' => $user->id, 'role' => $user->role]) ?>'>
</div>
// assets/js/app.js — reads config cleanly from its own file
const config = JSON.parse(document.getElementById('app-config').dataset.config);
const user = JSON.parse(document.getElementById('app-config').dataset.user);
1. Module Pattern (IIFE + ES Modules)
// assets/js/modules/user-table.js
const UserTable = (() => {
let tableInstance = null; // private — unreachable from outside
function init(config) { tableInstance = new DataTable('#users-table', config); }
function refresh() { tableInstance?.ajax.reload(); }
return { init, refresh }; // public API only
})();
export default UserTable;
// Named exports for shared utilities: assets/js/core/utils.js
export function debounce(fn, delay) { /* ... */ }
export function throttle(fn, limit) { /* ... */ }
Additional Guidance
Extended guidance for javascript-modern was moved to references/skill-deep-dive.md to keep this entrypoint compact and fast to load.
Use that deep dive for:
2. Async/Await — The Right Patterns
3. Production-Grade Fetch Wrapper
4. Destructuring — Beyond the Basics
5. Optional Chaining and Nullish Coalescing
6. Generators for Pagination / Lazy Data
7. WeakMap for Private Data and DOM Metadata
8. Proxy for Validation and Reactivity
9. Error Handling Strategy
10. Event Delegation (Performance Pattern)
11. Debounce and Throttle
12. LocalStorage with Expiry
13. const/letand Arrow Functionthis``
- Additional deep-dive sections continue in the reference file.
Decision Rules
| Condition |
Action |
| Code is shared across features |
Use explicit ES modules with narrow exports |
| Work is CPU-bound |
Move it off the main thread or backend |
| Legacy IIFE is stable and isolated |
Preserve it unless tested conversion adds value |
Capability Contract
Read and search are required. Editing and browser or test execution require authorisation; network access is optional.
Degraded Mode
Fallback: without execution, provide a patch plus exact lint, unit, and browser checks still required.
Domain Anti-Patterns
- Starting asynchronous work without handling rejection.
- Using global mutable state instead of module scope.
- Adding a dependency for a native language operation.
- Blocking the main thread with large synchronous transforms.
- Changing module format without checking runtime compatibility.
Inputs
| Artefact |
Required? |
Purpose |
| JavaScript target, runtime, code, and project conventions |
yes |
Select compatible language and module patterns |
Outputs
- Produce reviewed JavaScript, findings, tests, and compatibility notes.
1---2name: javascript-modern3description: Use when writing or reviewing modern JavaScript for browser or PHP-backed SaaS applications, including modules, asynchronous flows, error handling, language features, and performance.4---56# javascript-modern7Acknowledgement: Shared by Peter Bamuhigire, techguypeter.com, +256 784 464178.89<!-- dual-compat-start -->10## Use When1112- Modern JavaScript (ES6+) patterns for PHP+JavaScript SaaS apps: modules, async/await, destructuring, Proxy/Reflect, generators, WeakMap/WeakSet, optional chaining, error handling, and performance patterns. Use when writing JavaScript for web...1314## Workflow1516- For OOP-heavy browser modules, reusable UI widgets, or complex stateful workflows, pair with `references/javascript-patterns.md` and load `references/javascript-patterns.md`.17- For Node/runtime container work, pair with `docker-development`.1819## Evidence Produced2021| Category | Artifact | Format | Example |22|----------|----------|--------|---------|23| Correctness | JavaScript module test plan | Markdown doc covering async, generators, Proxy, and module boundary tests | `docs/web/js-module-tests.md` |2425## References2627- Use the `references/` directory for deep detail after reading the core workflow below.28- Use `references/javascript-advanced.md` when the task needs deeper ES language mechanics, async patterns, metaprogramming, or performance.29- Use `references/javascript-patterns.md` when the task involves OOP, prototypes, design patterns, event modules, or maintainable browser architecture.30<!-- dual-compat-end -->31Expert-level ES6+ patterns for PHP+JavaScript SaaS developers. Assumes fluency with variables, loops, and functions.3233## Architecture Rule (Non-Negotiable)3435JavaScript belongs in its own `.js` files. PHP only emits a `<script src="...">` tag or passes config via a single JSON data attribute. No `<?php echo $var ?>` scattered through JS files.3637```php38<!-- PHP emits one data attribute — no inline JS -->39<div id="app-config"40 data-config='<?= json_encode($config, JSON_HEX_APOS) ?>'41 data-user='<?= json_encode(['id' => $user->id, 'role' => $user->role]) ?>'>42</div>43```4445```javascript46// assets/js/app.js — reads config cleanly from its own file47const config = JSON.parse(document.getElementById('app-config').dataset.config);48const user = JSON.parse(document.getElementById('app-config').dataset.user);49```5051---5253## 1. Module Pattern (IIFE + ES Modules)5455```javascript56// assets/js/modules/user-table.js57const UserTable = (() => {58 let tableInstance = null; // private — unreachable from outside5960 function init(config) { tableInstance = new DataTable('#users-table', config); }61 function refresh() { tableInstance?.ajax.reload(); }6263 return { init, refresh }; // public API only64})();6566export default UserTable;6768// Named exports for shared utilities: assets/js/core/utils.js69export function debounce(fn, delay) { /* ... */ }70export function throttle(fn, limit) { /* ... */ }71```7273---7475## Additional Guidance7677Extended guidance for `javascript-modern` was moved to [references/skill-deep-dive.md](references/skill-deep-dive.md) to keep this entrypoint compact and fast to load.7879Use that deep dive for:80- `2. Async/Await — The Right Patterns`81- `3. Production-Grade Fetch Wrapper`82- `4. Destructuring — Beyond the Basics`83- `5. Optional Chaining and Nullish Coalescing`84- `6. Generators for Pagination / Lazy Data`85- `7. WeakMap for Private Data and DOM Metadata`86- `8. Proxy for Validation and Reactivity`87- `9. Error Handling Strategy`88- `10. Event Delegation (Performance Pattern)`89- `11. Debounce and Throttle`90- `12. LocalStorage with Expiry`91- `13. `const` / `let` and Arrow Function `this``92- Additional deep-dive sections continue in the reference file.9394## Decision Rules9596| Condition | Action |97|---|---|98| Code is shared across features | Use explicit ES modules with narrow exports |99| Work is CPU-bound | Move it off the main thread or backend |100| Legacy IIFE is stable and isolated | Preserve it unless tested conversion adds value |101102## Capability Contract103104Read and search are required. Editing and browser or test execution require authorisation; network access is optional.105106## Degraded Mode107108Fallback: without execution, provide a patch plus exact lint, unit, and browser checks still required.109110## Domain Anti-Patterns111112- Starting asynchronous work without handling rejection.113- Using global mutable state instead of module scope.114- Adding a dependency for a native language operation.115- Blocking the main thread with large synchronous transforms.116- Changing module format without checking runtime compatibility.117## Inputs118| Artefact | Required? | Purpose |119|---|---|---|120| JavaScript target, runtime, code, and project conventions | yes | Select compatible language and module patterns |121## Outputs122- Produce reviewed JavaScript, findings, tests, and compatibility notes.