Ai
1 Star 0 Fork 0

zhengmin/ES6

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Generator.html 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
zhengmin 提交于 2022-04-02 21:27 +08:00 . es6
<!-- <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// Generator 函数
// 我们建议大家星号总是放在function后面
// function* getInfo(){
// yield "hello"
// yield "world"
// return "end"
// }
// var info = getInfo();
// console.log(info.next()); // {value: 'hello', done: false}
// console.log(info.next()); // {value: 'world', done: false}
// console.log(info.next()); // {value: 'end', done: true}
function* foo() {
yield 1
yield 2
yield 3
yield 4
yield 5
return 6
}
for (let i of foo()) {
console.log(i); // 1 2 3 4 5 没有6
}
</script>
</body>
</html> -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./jquery-3.6.0.min.js"></script>
</head>
<body>
<script>
// $.getJSON("http://iwenwiki.com/api/generator/list.php", function (data) {
// $.getJSON("http://iwenwiki.com/api/generator/id.php", { id: data[0] }, function (data) {
// $.getJSON("http://iwenwiki.com/api/generator/name.php", { name: data.name }, function (data) {
// console.log(data);
// })
// })
// })
// 把一个异步的操作变成一个同步的操作,但是实质上还是异步
function ajax(url) {
$.getJSON(url, function (data) {
info.next(data)
})
}
function* getInfo() {
var ids = yield ajax("http://iwenwiki.com/api/generator/list.php");
var names = yield ajax("http://iwenwiki.com/api/generator/id.php?id=" + ids[0]);
var infos = yield ajax("http://iwenwiki.com/api/generator/name.php?name=" + names.name)
console.log(infos);
}
var info = getInfo();
info.next()
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wzm_love_coding/es6.git
git@gitee.com:wzm_love_coding/es6.git
wzm_love_coding
es6
ES6
master

搜索帮助