Generator函数

        // 类似于将foo()中yield 3; yield 4; 添加到bar()
        // 只输出调用的函数下的return值
        function* foo() {
            yield 3;
            yield 4;
            return "pubg";//在bar()的调用下,不会输出此值
        }
        function* bar() {
            yield 1;
            yield 2;
            yield* foo();
        }
        let res = bar();
        res.next(); //1
        res.next(); //2
        res.next(); //3
        res.next(); //4
        let resulit = res.next(); //undefind
        console.log(resulit);
        res = bar(); //重新为res赋值,上面res已经循环完毕
        for (let item of res) {
            console.log(item);
        }
上一篇:c/c++多线程模拟系统资源分配(并通过银行家算法避免死锁产生)


下一篇:<project标红报错 Cannot access alimaven (http;//maven.aliyun.com/nexus/content/repositories/central/)