119
rated 0 times
[
126]
[
7]
/ answers: 1 / hits: 23626
/ 7 Years ago, fri, september 29, 2017, 12:00:00
I have a function that performs an AJAX call, as such:
let retrieveData = (section, sectionItem, callback) => {
...
}
Where the second parameter is optional, i.e. in some cases that parameter is required, in others it isn't:
let data = retrieveData(aSection, aSectionItem, function(json)) {
...
});
and:
let data = retrieveData(aSection, undefined, function(json)) {
...
});
In the second instance I'd like to be able to omit the undefined
parameter and I believe assigning options/defaults by way of destructuring is the answer (as per this example: https://javascript.info/destructuring-assignment#smart-function-parameters), but I'm coming up short on how to structure the code.
More From » optional-parameters