Skip to content

HowProgrammingWorks/NativeContracts

Repository files navigation

JavaScript Native Contracts

  • Callable — Any value that can be invoked with () operator
  • Function — Callable object, with optional this binding or arrow
  • AsyncFunction — Promise-returning Function
  • Callback — A function passed to another function to be called later
  • Callback-last-error-first — Callback contract or convention (error, result) signature, where error is Error | null, and result is returned if no error
  • Thenable — Any object with a .then(fn) method
  • Promise — Thenable with then, catch, and finally
  • Iterable — Has [Symbol.iterator]() that returns an Iterator
  • AsyncIterable — Has [Symbol.asyncIterator]() that returns an AsyncIterator
  • Iterator — Has .next() returning { value, done } structure
  • Generator — A function producing an Iterator (sync or async), supporting next(), throw(), return()
  • Array-like — Object with indexed keys 0, 1, ... and numeric .length, but no array methods
  • Observable — Push-based data sours available for subscription
  • EventTarget — DOM standard interface with .addEventListener(event, handler)
  • EventEmitter — Node.js style event emitter with .on(event, handler) and .emit(event, ...args)
  • Stream — Abstraction for flow (readable/writable/duplex) with backpressure support