Trying to understand the different steps to the Promise implementation for D3 js.
Have two input files and promise them all:
JavaScript
x
2
1
Promise.all([jsonFile, txtFile]).then(input)
2
The array has been consolidated into one individual input, which might be called as a one-parameter function like:
JavaScript
1
5
1
function input(data) {
2
console.log(data[0]) // json
3
console.log(data[1]) // txt
4
}
5
Imagine I want to implement the second function as a two-parameter with the two inputs like function input(json, txt)
. What should happen in the then()
statement to make the code do so?
Thanks
Advertisement
Answer
If you want to implement input
function with two parameters:
JavaScript
1
4
1
function input(json, txt) {
2
// omitted
3
}
4
then you can use rest parameters [more]:
JavaScript
1
3
1
Promise.all([jsonFile, txtFile])
2
.then((data) => input(data))
3
or you can be more explicit:
JavaScript
1
3
1
Promise.all([jsonFile, txtFile])
2
.then(([json, txt]) => input(json, txt))
3