I'm sifting through some code and I don't get how this piece of code is able to pass arguments to a callback that takes no arguments.
We start with this object:
const oracleEndpoints = {
pancake: () => fetchPancake(),
lps: () => fetchLP(endpoints.lps), <-- endpoints.lps is an API url
};
And this map:
const oracleToIds = new Map()
oracleToIds.set("lps", ["png-snob-avax", "png-png-avax"])
oracleToIds.set("pancake", ["WBNB", "BREW"])
Now this is the part I don't get:
const promises = oracleToIds.keys().map(key => oracleEndpoints[key](oracleToIds.get(key)));
oracleEndpoints[key]
is an anonymous callback (() => fetchPancake()
or () => fetchLP(endpoints.lps)
) and oracleToIds.get(key)
is an array of strings.
What's going on in this expression oracleEndpoints[key](oracleToIds.get(key))
then where an unparametised callback is passed an array?
How is it able to do this?