I have reviewed articles of various promise implementations, all of which indicate that it is necessary to maintain a _ deferreds
to save the callback function set information registered by the then method, and some implementations maintain onResolvedCallback
and onRejectedCallback
to maintain.
but many don"t explain why _ deferreds
needs to be an array. Or the description of _ deferreds
is relatively vague, and I can"t understand it directly until I get home with the technology.
for example, in this article
the author says that the then method can be called multiple times by the same promise, so it needs to be initialized to an array. I don"t know when the then method will be called multiple times by the same promise.
ask for a code to illustrate this situation!