Objects, classes and modules
This part of the JavaScript course starts with an object literal, its property descriptors and Object.keys and entries, and the prototype chain explains what a lookup walks. Constructor functions show what new does, and a class writes the same thing with fields, private members, extends and super, plus static members and a factory. Modules come in both systems: an ES module with import and a CommonJS file with require. A small inventory made of three modules and a test file closes the part.
061
Object literals and property access
a literal and the two ways to read it, computed keys, shorthand methods and the this they use, the missing key that answers undefined and the read of a field of null
Open
062
Property descriptors
defineProperty, the four flags and the false they default to, getters and setters, a key that Object.keys and JSON cannot see
Open
063
Object.keys, values and entries
keys, values and entries as arrays, fromEntries to build an object back, Object.assign and its target, the shallow copy and the getter it turns into a value
Open
064
The prototype chain
a prototype as another object, walking the chain with getPrototypeOf, own against inherited keys in a for-in loop, and where the chain ends
Open
065
Constructor functions and new
what new does with this, a method shared on the prototype, the call that forgot new, and instanceof through the chain
Open
066
Classes: syntax and what they add
the constructor and the methods, non-enumerable methods, the call that needs new, and a class binding that is not hoisted
Open
067
Class fields and private members
public fields initialised per instance, #private members and their parse error from outside, the brand check with in, and a static block
Open
068
Inheritance with extends and super
extends and the super call, an override that still calls the parent, instanceof across the chain, and this before super
Open
069
Static members and factories
a static counter, static members a subclass inherits, a factory that returns a class with its own state, and one factory making two classes
Open
070
ES modules: import and export
package.json with type module, named and default exports, a renamed import, re-exports and a namespace, and the SyntaxError of a missing export
Open
071
CommonJS: require and module.exports
require and module.exports, a module that runs once and is cached, why exports is not module.exports, and a function or a JSON file as the export
Open
072
A small project: an inventory in three modules
an Item with a private quantity, an Inventory over a Map, a report module and its money format, a main program, and a test file with node:assert
Open