I'm trying to understand Promises and their optional arguments.
(I'm assuming that because the arguments are optional, that too few are acceptable, and that too many arguments are also acceptable).
As an example:
let myPromise = new Promise(function(first, second, third) {
let x = 0;
if (x == 0) { //<<true
second();
} else {
third();
}
});
myPromise.then(
function() {
console.log("1");
},
function() {
console.log("2");
}
);
Runs the second function and outputs "2".
let myPromise = new Promise(function(first, second, third) {
let x = 0;
if (x != 0) { //<<false
second();
} else {
third();
}
});
myPromise.then(
function() {
console.log("1");
},
function() {
console.log("2");
}
);
Also runs the second function and outputs "2".
In the first case, is the Promise calling the function by name; And in the second case, calling the function by position?
How exactly does a Promise know which function to call?