<html>
<head>
<meta charset="utf-8">
<title>生成器函数实例</title>
</head>
<body>
<script type="text/javascript">
// 实现需求1s钟后输出111 然后延迟2s后输出222 然后再延迟3s钟后输出333
// 回调地狱做法
// setTimeout(()=>{
// console.log(111)
// setTimeout(()=>{
// console.log(222)
// setTimeout(()=>{
// console.log(333)
// },3000)
// },2000)
// },1000)
// 生成器函数做法
function one(){
setTimeout(()=>{
console.log(111)
interator.next()
},1000)
}
function two(){
setTimeout(()=>{
console.log(222)
interator.next()
},2000)
}
function three(){
setTimeout(()=>{
console.log(333)
interator.next()
},3000)
}
function * gen(){
yield one();
yield two();
yield three();
}
let interator = gen()
interator.next()
</script>
</body>
</html>