Skip to content

Instantly share code, notes, and snippets.

@doggy8088
Last active February 9, 2020 02:34
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doggy8088/1b546083a607cd06233137a8dba4f00a to your computer and use it in GitHub Desktop.
Save doggy8088/1b546083a607cd06233137a8dba4f00a to your computer and use it in GitHub Desktop.
這個人不會寫 Promise 之討論串整理
var image = new Image();
image.src = filename;
image.onload = function() {
// use image
}
fetch(filename).then(res => {
res.blob().then(blob => {
createImageBitmap(blob).then( image => {
// use image
}
}
});
fetch(filename)
.then(res => res.blob())
.then(blob => createImageBitmap(blob))
.then(image => image.whatever());
(async function aa() {
var res = await fetch(filename);
var blob = await res.blob();
var image = await createImageBitmap(blob);
console.log(image);
})();
(async function aa() {
console.log(await createImageBitmap(await (await fetch(filename)).blob()))
})()
@amazingandyyy
Copy link

thx for recording.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment