promises
This commit is contained in:
parent
a68022a8d6
commit
04b2fcfba2
17 changed files with 304 additions and 137 deletions
23
archive/promise/thenable.js
Normal file
23
archive/promise/thenable.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
function loadScript(src) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
let script = document.createElement('script');
|
||||
script.src = src;
|
||||
|
||||
script.onload = () => resolve(script);
|
||||
script.onerror = () => reject(new Error("Script load error: " + src));
|
||||
|
||||
document.head.append(script);
|
||||
});
|
||||
}
|
||||
loadScript("/article/promise-chaining/one.js")
|
||||
.then(script => {
|
||||
return {
|
||||
then(resolve, reject) {
|
||||
setTimeout(() => resolve(script), 1000);
|
||||
}
|
||||
};
|
||||
})
|
||||
.then(function(script) {
|
||||
alert(one);
|
||||
});
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue