3đź‘Ť
It’s the parameter declared for that callback function:
Alert.YesNo("Tem certeza?", "Você está...permanentemente!").then(res => {
// --------------------------------------------------------------^
Doesn’t have to be called res
, the name doesn’t matter. I’m guessing “res” is for “resposta” (we often also use it in English-centric programming, for “response”).
The YesNo
dialog box fulfills its promise with a flag for the answer. res
is the flag.
The code within that then
handler calls another function, setLikeCanceled
, which also returns a promise. The then
handler on that promise is written to use res
as the parameter name. This is a different parameter than the first one, containing the fulfillment value from setLikeCanceled
. (Having the same identifier used in two nested scopes like that is called shadowing: The inner identifier shadows the outer one, making it inaccessible in the inner scope.) Is the inner res
, not the outer one, that gets assigned to this.document.status
.
0đź‘Ť
In the function above, the setLikeCanceled method is running asynchronously. The result of the function is being handled via a native Javascript promise (we can tell because .then() and .catch() are reserved for promises).
When it finishes executing, the returned value can then be used in whatever way your code needs BUT you need that value to be set before your function is allowed to proceed. In this case, “res” is just a reference to the result of the promise. I can’t tell you exactly what it stands for but could be either resolution or response. It doesn’t really matter as you could change that to whatever you want. It’s not a reserved word in Javascript.
Promises are very common in AJAX calls where there’s some lag time before a value is set because of a web service call or because you need to reach out to a database.