Created
March 20, 2018 02:08
-
-
Save archangel-irk/2cf45172df90f5dfc4cdf6d2bcc2740b to your computer and use it in GitHub Desktop.
Required Parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function requiredParam (param) { | |
const requiredParamError = new Error( | |
`Required parameter, "${param}" is missing.` | |
); | |
// preserve original stack trace | |
if (typeof Error.captureStackTrace === ‘function’) { | |
Error.captureStackTrace( | |
requiredParamError, | |
requiredParam, | |
); | |
} | |
throw requiredParamError; | |
} | |
function findUsersByRole ({ | |
role = requiredParam('role'), | |
withContactInfo, | |
includeInactive, | |
} = {}) {...} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://medium.freecodecamp.org/elegant-patterns-in-modern-javascript-roro-be01e7669cbd