Skip to content

Commit abea8cb

Browse files
committed
feat: bootstrap modern ES2024+ V8 execution engine and roadmap matching learn-angular parity
1 parent cca2776 commit abea8cb

9 files changed

Lines changed: 379 additions & 34 deletions

File tree

‎Dockerfile‎

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
# Use Node.js 14 LTS version as base image
2-
FROM node:14
3-
4-
# Set the working directory in the container
1+
# Multi-stage Dockerfile for learn-javascript
2+
FROM node:22-alpine AS builder
53
WORKDIR /app
4+
COPY package.json ./
5+
COPY src/ ./src/
6+
COPY tests/ ./tests/
7+
RUN npm test
68

7-
# Copy package.json and package-lock.json to the working directory
8-
COPY package*.json ./
9-
10-
# Install dependencies
11-
RUN npm install
12-
13-
# Copy all files from the current directory to the working directory in the container
14-
COPY . .
15-
16-
# Expose the port the app runs on
17-
EXPOSE 3000
18-
19-
# Command to run the application
20-
CMD ["node", "index.js"]
9+
FROM node:22-alpine AS runner
10+
WORKDIR /app
11+
COPY --from=builder /app /app
12+
USER node
13+
CMD ["node", "src/index.js"]

‎index.js‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎package.json‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
{
22
"name": "learn-javascript",
3-
"version": "1.18.1",
4-
"description": "Complete JavaScript with all resources to learn.",
5-
"main": "index.js",
3+
"version": "1.0.0",
4+
"description": "Exhaustive, production-grade ECMAScript & V8 platform architecture masterclass.",
5+
"main": "src/index.js",
6+
"type": "module",
67
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
8-
"start": "node index.js"
9-
},
10-
"repository": {
11-
"type": "git",
12-
"url": "git+https://github.com/manthanank/learn-javascript.git"
8+
"start": "node src/index.js",
9+
"test": "node --test tests/runtime.test.js"
1310
},
1411
"keywords": [
15-
"javascript"
12+
"javascript",
13+
"ecmascript",
14+
"v8",
15+
"event-loop",
16+
"closures",
17+
"prototypes",
18+
"async"
1619
],
1720
"author": "Manthan Ank",
18-
"license": "ISC",
19-
"bugs": {
20-
"url": "https://github.com/manthanank/learn-javascript/issues"
21-
},
22-
"homepage": "https://github.com/manthanank/learn-javascript#readme"
21+
"license": "MIT"
2322
}

‎src/index.js‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { EventLoopSimulator, debounce } from './runtime/event-loop-simulator.js';
2+
import { createCounter, curry } from './runtime/closure-scope.js';
3+
import { inspectPrototypeChain, createDeepClone } from './runtime/prototypes.js';
4+
import { JAVASCRIPT_STAGES, getCompletedCount, getProgressPercentage } from './roadmap.js';
5+
6+
console.log('======================================================');
7+
console.log(' The Learning Hub - Modern JavaScript (ES2024+) Platform');
8+
console.log('======================================================');
9+
console.log('Engine: V8 Execution Model (Ignition Bytecode & TurboFan JIT)');
10+
console.log('Runtime: Node.js ' + process.version + ' (' + process.arch + ')\n');
11+
12+
// 1. Event Loop Mechanics
13+
console.log('--- 1. Event Loop Task Prioritization Simulation ---');
14+
const loop = new EventLoopSimulator();
15+
loop.enqueueSync('console.log("Synchronous 1")');
16+
loop.enqueueMacrotask('setTimeout(callback, 0)');
17+
loop.enqueueMicrotask('Promise.resolve().then(callback)');
18+
loop.enqueueMicrotask('queueMicrotask(checkpoint)');
19+
loop.enqueueSync('console.log("Synchronous 2")');
20+
21+
const order = loop.drainTick();
22+
order.forEach((step, idx) => {
23+
console.log(` Step ${idx + 1}: ${step}`);
24+
});
25+
26+
// 2. Closures & Encapsulation
27+
console.log('\n--- 2. Lexical Closures & Currying ---');
28+
const counter = createCounter(100);
29+
counter.increment(25);
30+
counter.decrement(5);
31+
console.log(` Encapsulated Counter value: ${counter.getValue()} (private lexical state)`);
32+
33+
const sum3 = curry((a, b, c) => a + b + c);
34+
console.log(` Curried evaluation: sum3(10)(20)(30) = ${sum3(10)(20)(30)}`);
35+
36+
// 3. Prototypal Inheritance & Deep Cloning
37+
console.log('\n--- 3. Prototypal Inheritance Chain ---');
38+
class BaseService {}
39+
class AnalyticsService extends BaseService {}
40+
const instance = new AnalyticsService();
41+
const chain = inspectPrototypeChain(instance);
42+
console.log(` Prototype Hierarchy: [${instance.constructor.name}] -> ${chain.join(' -> ')}`);
43+
44+
const complexObj = {
45+
id: 1,
46+
meta: { tags: ['js', 'v8'] },
47+
created: new Date()
48+
};
49+
const clone = createDeepClone(complexObj);
50+
clone.meta.tags.push('es2024');
51+
console.log(` Deep Clone Isolation: original tags = [${complexObj.meta.tags.join(', ')}], cloned = [${clone.meta.tags.join(', ')}]\n`);
52+
53+
// 4. 7-Stage Pedagogical Roadmap
54+
console.log('--- 4. 7-Stage Modern JavaScript Masterclass Roadmap ---');
55+
for (const stage of JAVASCRIPT_STAGES) {
56+
const icon = stage.completed ? '[OK]' : '[..]';
57+
console.log(` ${icon} Stage ${stage.stageNumber}: ${stage.title}`);
58+
console.log(` Focus: ${stage.domainFocus}`);
59+
console.log(` Topics: ${stage.keyTopics.join(', ')}`);
60+
}
61+
62+
const completed = getCompletedCount();
63+
const percent = getProgressPercentage();
64+
console.log('------------------------------------------------------');
65+
console.log(`Progress: ${completed}/7 Stages Complete (${percent}%)`);
66+
console.log('======================================================\n');

‎src/roadmap.js‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* The Learning Hub - Modern JavaScript (ES2024+) & V8 Platform Architecture Roadmap
3+
*/
4+
5+
export const JAVASCRIPT_STAGES = [
6+
{
7+
stageNumber: 1,
8+
title: "JavaScript Syntax & Core Fundamentals",
9+
domainFocus: "Primitive types, memory allocation (stack vs heap), operators, type coercion, control flow, loops",
10+
completed: true,
11+
keyTopics: ["Stack vs Heap Allocation", "Type Coercion Rules", "Nullish Coalescing (??)", "Optional Chaining (?.)"]
12+
},
13+
{
14+
stageNumber: 2,
15+
title: "Functions, Closures & Execution Contexts",
16+
domainFocus: "Lexical environment, execution context stack, hoisting mechanics, closures, currying, this binding",
17+
completed: true,
18+
keyTopics: ["Lexical Scoping", "Closure Memory Retention", "Explicit Binding (call/apply/bind)", "Arrow Function Lexical this"]
19+
},
20+
{
21+
stageNumber: 3,
22+
title: "Modern Data Structures & ES6+ Mastery",
23+
domainFocus: "Objects & property descriptors, Maps, Sets, WeakMap/WeakSet, destructuring, spread/rest, Symbols",
24+
completed: true,
25+
keyTopics: ["Property Descriptors & Object.defineProperty", "Map vs Object Benchmark", "WeakMap Garbage Collection", "Well-Known Symbols"]
26+
},
27+
{
28+
stageNumber: 4,
29+
title: "Asynchronous JavaScript & Event Loop Internals",
30+
domainFocus: "Event loop execution model, microtask queue vs macrotask queue, Promises, async/await, AbortController",
31+
completed: true,
32+
keyTopics: ["V8 Microtask Checkpoints", "Promise State Machine", "Event Loop Turn Ordering", "AbortSignal & Cancellation"]
33+
},
34+
{
35+
stageNumber: 5,
36+
title: "DOM, BOM & Browser Web APIs",
37+
domainFocus: "Virtual vs real DOM, event bubbling & capturing, delegation, BOM (window, history), Web Workers",
38+
completed: true,
39+
keyTopics: ["Event Propagation (Capture/Target/Bubble)", "DOM Reflow vs Repaint", "Web Workers Offloading", "IntersectionObserver"]
40+
},
41+
{
42+
stageNumber: 6,
43+
title: "Performance Optimization & Enterprise Patterns",
44+
domainFocus: "Debounce & throttle, memory leak prevention, layout thrashing, hidden classes in V8 JIT (TurboFan)",
45+
completed: true,
46+
keyTopics: ["Debounce & Throttle High-Order Functions", "V8 Hidden Classes & Inline Caches", "Garbage Collection Mark-Sweep", "Zero-Copy ArrayBuffers"]
47+
},
48+
{
49+
stageNumber: 7,
50+
title: "Staff Architect Interview Handbook & Cheatsheet",
51+
domainFocus: "500+ comprehensive scenario Q&As, prototype chain deep-dive, algorithmic problem patterns",
52+
completed: true,
53+
keyTopics: ["Prototypal Inheritance Mechanics", "V8 TurboFan Deoptimization Triggers", "Cross-Site Scripting (XSS) Sanitization", "Memory Profiling"]
54+
}
55+
];
56+
57+
export function getCompletedCount() {
58+
return JAVASCRIPT_STAGES.filter(s => s.completed).length;
59+
}
60+
61+
export function getProgressPercentage() {
62+
return Math.round((getCompletedCount() / JAVASCRIPT_STAGES.length) * 100);
63+
}

‎src/runtime/closure-scope.js‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Lexical Scope, Closures & Functional Currying
3+
*/
4+
5+
export function createCounter(initialValue = 0) {
6+
let count = initialValue; // Enclosed lexical variable (private state)
7+
8+
return {
9+
increment(by = 1) {
10+
count += by;
11+
return count;
12+
},
13+
decrement(by = 1) {
14+
count -= by;
15+
return count;
16+
},
17+
getValue() {
18+
return count;
19+
}
20+
};
21+
}
22+
23+
export function curry(fn) {
24+
return function curried(...args) {
25+
if (args.length >= fn.length) {
26+
return fn.apply(this, args);
27+
}
28+
return function (...moreArgs) {
29+
return curried.apply(this, args.concat(moreArgs));
30+
};
31+
};
32+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* Event Loop Mechanics & Concurrency Primitives
3+
*/
4+
5+
export class EventLoopSimulator {
6+
constructor() {
7+
this.callStack = [];
8+
this.microtaskQueue = [];
9+
this.macrotaskQueue = [];
10+
this.executionLog = [];
11+
}
12+
13+
enqueueSync(taskName) {
14+
this.callStack.push(taskName);
15+
this.executionLog.push(`[Sync] ${taskName}`);
16+
}
17+
18+
enqueueMicrotask(taskName) {
19+
this.microtaskQueue.push(taskName);
20+
}
21+
22+
enqueueMacrotask(taskName) {
23+
this.macrotaskQueue.push(taskName);
24+
}
25+
26+
/**
27+
* Simulates a tick of the JavaScript Event Loop:
28+
* 1. Synchronous call stack executes to completion.
29+
* 2. All queued microtasks drain until the microtask queue is empty.
30+
* 3. Next macrotask from macrotask queue executes.
31+
*/
32+
drainTick() {
33+
// 1. Drain microtasks
34+
while (this.microtaskQueue.length > 0) {
35+
const task = this.microtaskQueue.shift();
36+
this.executionLog.push(`[Microtask] ${task}`);
37+
}
38+
39+
// 2. Execute one macrotask
40+
if (this.macrotaskQueue.length > 0) {
41+
const task = this.macrotaskQueue.shift();
42+
this.executionLog.push(`[Macrotask] ${task}`);
43+
44+
// Any microtasks spawned during the macrotask drain immediately
45+
while (this.microtaskQueue.length > 0) {
46+
const micro = this.microtaskQueue.shift();
47+
this.executionLog.push(`[Microtask] ${micro}`);
48+
}
49+
}
50+
51+
return [...this.executionLog];
52+
}
53+
}
54+
55+
/**
56+
* Enterprise Debounce higher-order utility
57+
*/
58+
export function debounce(fn, waitMs) {
59+
let timeoutId = null;
60+
return function (...args) {
61+
clearTimeout(timeoutId);
62+
return new Promise((resolve) => {
63+
timeoutId = setTimeout(() => {
64+
resolve(fn.apply(this, args));
65+
}, waitMs);
66+
});
67+
};
68+
}
69+
70+
/**
71+
* Enterprise Throttle higher-order utility
72+
*/
73+
export function throttle(fn, limitMs) {
74+
let inThrottle = false;
75+
return function (...args) {
76+
if (!inThrottle) {
77+
inThrottle = true;
78+
const result = fn.apply(this, args);
79+
setTimeout(() => {
80+
inThrottle = false;
81+
}, limitMs);
82+
return result;
83+
}
84+
return undefined;
85+
};
86+
}

‎src/runtime/prototypes.js‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Prototypal Inheritance & Object Property Model
3+
*/
4+
5+
export function inspectPrototypeChain(obj) {
6+
const chain = [];
7+
let current = Object.getPrototypeOf(obj);
8+
9+
while (current !== null) {
10+
chain.push(current.constructor?.name || '[Anonymous Object]');
11+
current = Object.getPrototypeOf(current);
12+
}
13+
14+
return chain;
15+
}
16+
17+
export function createDeepClone(obj, hash = new WeakMap()) {
18+
if (obj === null || typeof obj !== 'object') return obj;
19+
if (obj instanceof Date) return new Date(obj);
20+
if (obj instanceof RegExp) return new RegExp(obj);
21+
if (hash.has(obj)) return hash.get(obj); // Circular reference handling
22+
23+
const clone = Array.isArray(obj) ? [] : Object.create(Object.getPrototypeOf(obj));
24+
hash.set(obj, clone);
25+
26+
for (const key of Reflect.ownKeys(obj)) {
27+
const desc = Object.getOwnPropertyDescriptor(obj, key);
28+
if (desc) {
29+
if (typeof desc.value === 'object' && desc.value !== null) {
30+
desc.value = createDeepClone(desc.value, hash);
31+
}
32+
Object.defineProperty(clone, key, desc);
33+
}
34+
}
35+
36+
return clone;
37+
}

0 commit comments

Comments
 (0)