xtodo JavaScript js

Prototype Based Object System (Object Based Inheritance)

History of JavaScript Constructors and Class Complexity

Unnecessary and Bad Complexity in JavaScript

2015 Addition of the Keyword Class


This chapter, is detailed explanation of these.

Where does the async part came from?

when JavaScript runs new promise(executor), it creates a internal while loop so it doesnt wait for the executor to finish.

the control of calling new promise(executor) is immediately released.

in the while loop, JavaScript runs the executor and also runs your code that follows the new promise(executor).

the while loop checks the state of the promise. When the state is settled, it exit the internal while loop.

so you have the illusion of parallel execution of the promise code.

but because JavaScript is so-called single threaded, its actually doing a internal while loop to emulate the async effect.

gah, it's fairly complicated to understand how JavaScript async works, while it being so-called single-threaded.

you can't understand it unless you have some understanding of how os thread or process works and js's interaction with browser.

basically, the question is, if i can call setTimeout in js, what is js actually doing that seems to have the illusion of async or concurrent or parallel.

big session chatting with ai. the round-the-clock oracle.

it is telling me about stack, macrotask, microtask.

ai chat link in next post.

https://grok.com/share/c2hhcmQtMi1jb3B5_885dd517-091d-4d63-b166-aaf25ac5997e

The Error cause feature, standardized in ECMAScript 2022, allows developers to chain errors by passing the original error as a property in the Error constructor's options object. This is achieved using the syntax new Error("message", { cause: originalError }), which preserves the original error's stack trace and type for better debugging.

JavaScript private class fields are declared by prefixing the property name with a hash symbol (#), ensuring they are strictly inaccessible from outside the class scope. This feature, standardized in ES2022, provides true encapsulation enforced by the JavaScript engine, preventing access, enumeration, or deletion via standard object methods.

Key characteristics include:

  • Hard Privacy: Private fields are scoped to the class body; subclasses cannot access parent private fields, and external code cannot retrieve them even with reflection.
  • Declaration Required: The field must be declared in the class body (e.g., #field;) before it can be assigned or accessed; creating it dynamically via this.#newField results in a syntax error.
  • Name Collision Avoidance: The # is part of the name, so a private field #x never clashes with a public property x.
  • Static Support: Private static fields (static #field) allow class-level private data accessible only via the class name (e.g., MyClass.#field), not via this.

(ai answer)

class MyClass {
  // Declare private field
  #privateValue = 42;

  constructor() {
    // Accessible within the class
    console.log(this.#privateValue); // 42
  }
}

const instance = new MyClass();
// console.log(instance.#privateValue); // SyntaxError   
xtodo

String.raw Property???

The first argument has a property key "raw". Its value is the raw string.

make functional programing example

YouTube stars flying 2025-05-12
YouTube stars flying 2025-05-12
  • 2025-04-29
  • JavaScript fix snow fall page. make it all just fall, no bounce back.
  • make it number of flakes according to screen size
  • JS DOM: Falling Snow Effect
js iterator 2025-04-26 192d7
js iterator 2025-04-26 192d7
const xx = Array(4).fill(0).map((x, i) => x + i);
console.log(xx);
// [ 0, 1, 2, 3 ]

// yy = xx[Symbol.iterator];

// console.log( yy )

// console.log( yy() .next() )

console.log( xx[Symbol.iterator]().next(), );
// { value: 0, done: false }

console.log( xx[Symbol.iterator]().next(), );
// { value: 0, done: false }

/*
the complex javascript iterator generator interface fucks.

here, first is the complexity of no range function.
you got the fill method patch to deal with that.

then, am trying to deconstruct the iteratable interface, trying to get its next value.
but apparantly it resets.

very complex, because the iterable contains a property of type symbol, named Symbol.iterator.
it's value must be a function.
and it must return a object, this object must have a next property, and this property's value must be a function.
this is why u get this funky
xx[Symbol.iterator]().next()

its return value, is a object, that contains value and done keys.

yet, somehow it resets. am unable to get it to 0, 1, 2, 3, etc.
 */
xtodo

js walk dir

Georrg, 11/03/2022 @XahLee standard library has walk and walkSync functions

import { walkSync } from "https://deno.land/std@0.162.0/fs/walk.ts";

for (const entry of walkSync(".")) {
console.log(entry.path);
}
js TypeScript george 2022-04-19
JavaScript TypeScript george 2022-04-19
js todo 2021-11-21 tmKkW
JavaScript todo 2021-11-21 tmKkW

missing some. create new page for them.

js this-binding argument

bryan forbs js 2026-02-01 2a969
bryan forbs js 2026-02-01 2a969
// nasty problem in JavaScript involving this-binding

function MakeObj(x) {
this.p = x;
return "lol";
}

function OhMyGodMakeObj(x) {
this.p = x;
return {};
}

const niceObj = new MakeObj(3);
console.assert(niceObj.p === 3);

const godObj = new OhMyGodMakeObj(3);
console.assert(godObj.p === 3, "omg, no work");
// Assertion failed: omg, no work
// oddity in JavaScript involving this-binding.
// a magic “this” bultin var, nothing to do with object oriented programing.

function addone(x) {
return this + x;
}

console.assert(addone.call(3, 4) === 7);

/*
this means, people can write all functions this way,
and the new call syntax is
funname.call(args...)
instead of just
funname.(args...)
*/

/*

the problem here is, in typical programing engineering fashion of speaking, JavaScript leaked the this-binding mechanism for its so-called dispatch in its object-oriented way.

it should generate a error instead, when function use this-binding without being a method.

*/