生成器函数的认识
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			// 生成器函数是一特殊的函数
			// 异步编程   纯回调函数  node fs ajax mongodb
			function * fn(){
				console.log('hello fn');
			}
			let result = fn();
			// console.log(result);
			
			
			// 输出函数的内容
			result.next();
		</script>
		
		<script>
			// yield  函数代码的分隔符
			function * fn(){
				// console.log(111);
				yield 'one';
				// console.log(222);
				yield 'two';
				// console.log(333);
				yield 'three';
				// console.log(444);
			}
			// let result = fn();
			// result.next();
			// console.log(result.next());
			// result.next();
			// result.next();
			// result.next();
			
			// 遍历yield
			for(let v of fn()){
				console.log(v);
			}
		</script>
	</body>
</html>

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号