Skip to content

Instantly share code, notes, and snippets.

@JustinSDK
Created May 7, 2019 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustinSDK/0ffe59c8c5a885933cadf936251539f2 to your computer and use it in GitHub Desktop.
Save JustinSDK/0ffe59c8c5a885933cadf936251539f2 to your computer and use it in GitHub Desktop.
es7-iterator-async-await.js
// 自行實作迭代器
const vertex1 = {
x: 1,
y: 2,
z: 3,
[Symbol.iterator]() {
const keys = Object.keys(this);
let i = 0;
return {
next: () => {
return {
value: (async () => {
return this[keys[i++]];
})(),
done: keys.length === i - 1
};
}
};
}
};
async function main() {
for(let p of vertex1) {
console.log(await p);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment