Created
May 7, 2019 05:43
-
-
Save JustinSDK/0ffe59c8c5a885933cadf936251539f2 to your computer and use it in GitHub Desktop.
es7-iterator-async-await.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 自行實作迭代器 | |
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