Skip to content

Instantly share code, notes, and snippets.

@projektorius96
Last active December 29, 2019 08:40
Show Gist options
  • Save projektorius96/bc5413fb7acd08781d7766c704ac1f88 to your computer and use it in GitHub Desktop.
Save projektorius96/bc5413fb7acd08781d7766c704ac1f88 to your computer and use it in GitHub Desktop.
// https://stackoverflow.com/questions/32518615/skip-arguments-in-a-javascript-function
// A WAY
function skipSomeParams(undefined, undefined, undefined, arg4, arg5) {
console.log(undefined, undefined, undefined, arg4, arg5)
}
const skip = (num) => new Array(num);
skipSomeParams(...skip(3), "a", "b")
// undefined, undefined, undefined, "a", "b"
// B WAY – Destructing assignment
function selectParaFromObj({somePara1, justPara2, someUndefinedPara3, someOtherParas}) {
console.log(justPara2, someOtherParas)
}
// with no arguments passed function must be invoked such a way:
// selectParaFromObj({/* with curly brackets within the round brackets */})
selectParaFromObj({justPara2: "String passed", someOtherParas: 10})
// String passed 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment