In the following code, to run the third then, and then the first one, is the second again, may be linked to the setTime, but I don't know why,
Please directly copying my code, and then save as HTML, can run in the browser, notice that I output log
Promise. Resolve (' foo ')
//1. The Receive "foo" concatenate "bar" to it and resolve that the to the next then
Then (function (string) {
Return new Promise (function (resolve, reject) {
SetTimeout (function () {
String +='bar';
Resolve (string);
}, 1);
});
})
//2. The receive "foobar", register a callback function to work on the string
//and print it to the console, but not before the return of the unworked on
//the string to the next then
Then (function (string) {
SetTimeout (function () {
String +='baz';
The console. The log (string);
},
1)Return a string;
})
//3. Print helpful messages about how the code in this section will be run
//before the string is later processed by the mocked asynchronous code in the
//the prior then block.
Then (function (string) {
The console. The log (" Last Then: oops... Didn 't bother to instantiate the and return "+
"A promise in the prior then so the sequence may be a bit" +
"Surprising");
//Note that ` string ` will not have the 'baz' bit of it at this point, this
//is because we mocked that to happen asynchronously with a setTimeout function
The console. The log (string);
});
</script>
<body>