Skip to content

Instantly share code, notes, and snippets.

@basarat
Last active June 23, 2016 09:53
Show Gist options
  • Save basarat/482318f64674fb5f9038602ce63cc661 to your computer and use it in GitHub Desktop.
Save basarat/482318f64674fb5f9038602ce63cc661 to your computer and use it in GitHub Desktop.
requied.js
/**
* Called if a parameter is missing and
* the default value is evaluated.
*/
function mandatory() {
throw new Error('Missing parameter');
}
function foo(mustBeProvided = mandatory()) {
return mustBeProvided;
}
foo()

Error: Missing parameter

foo(123)

Ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment