Skip to content

Instantly share code, notes, and snippets.

@coverboy
coverboy / README.md
Created August 3, 2018 01:02 — forked from MarkTiedemann/README.md
An Easier Way to Enforce Required Parameters in ES6

An Easier Way to Enforce Required Parameters in ES6

Expands on Handling required parameters in ECMAScript 6 by Axel Rauschmayer.

The idea (which is credited to Allen Wirfs-Brock) is, in essence, to use default parameter values to call a function which throws an Error if the parameter is missing:

const throwIfMissing () => { throw new Error('Missing parameter') }