• 关于es6中的yield


    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <meta charset="utf-8">
        <script src="../node_modules/babel-core/browser.js"></script>
        <script src="../node_modules/babel-polyfill/dist/polyfill.js"></script>
    </head>
    <body>
        <script type="text/babel">
            var demo = () => {
                console.log('this is demo')
            }
            demo()
    
            function* a(){
                console.log(11)
                yield 'kevin';
    console.log(
    22); yield 'ivan'; console.log(33); yield 'wuhan'; return 'yes'; } var b = a(); console.log(b.next()) console.log(b.next()) console.log(b.next()) console.log(b.next()) /* *调用Generator a方法不会执行函数代码,只有调用next方法才会执行 *每次调用next方法遇到yield就会停止运行,如果要继续运行下面的代码需要再次调用next方法 *next方法返回一个json对象,包含两个属性value和done,value是yield后面的值,done的值为false或者true,代表方法里的所有代码是否都已执行完成 */ </script> </body> </html>

    npm install babel-core@old //安装5.x的版本

    babel-core默认只支持es6语法,对新的API并不支持,如若要支持支持转换完整的ES6特性,需要安装babel-polyfill

    npm install babel-polyfill

  • 相关阅读:
    IDEA常用快捷键
    IDEA的使用
    IDEA的常用设置
    IDEA的下载安装
    004-解决多线程安全问题
    002-多线程的创建
    Java中字符串与日期之间的转换
    select标签的字体居中问题
    IntelliJ IDEA常用快捷键
    div小技巧之子元素垂直居中
  • 原文地址:https://www.cnblogs.com/toward-the-sun/p/7751982.html
Copyright © 2020-2023  润新知