Last active
December 29, 2019 08:40
-
-
Save projektorius96/bc5413fb7acd08781d7766c704ac1f88 to your computer and use it in GitHub Desktop.
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
// 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