mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-02 08:35:07 +08:00
Represent ordinary JavaScript arrays with hole, value, and explicit-undefined states; add sparse side storage and carry missing values through the frontend, native backends, runtime, and Node-facing consumers.
22 lines
642 B
TypeScript
22 lines
642 B
TypeScript
// Both operands of instanceof evaluate before its result is chosen. A hole
|
|
// on the left behaves as undefined and returns false with a present class;
|
|
// a hole on the right still throws even when the left is missing.
|
|
class Item {}
|
|
class Child extends Item {}
|
|
|
|
const values: Item[] = [];
|
|
values[1] = new Item();
|
|
const classes: (typeof Item)[] = [];
|
|
classes[1] = Item;
|
|
|
|
const missingValue = values[0];
|
|
const presentClass = classes[1];
|
|
console.log(missingValue instanceof presentClass);
|
|
|
|
const missingClass = classes[0];
|
|
try {
|
|
console.log(missingValue instanceof missingClass);
|
|
} catch (error) {
|
|
console.log(error instanceof TypeError);
|
|
}
|