【问题标题】:Using co coroutine library client-side in browser?在浏览器中使用协程库客户端?
【发布时间】:2016-10-13 00:09:42
【问题描述】:

如何使用

co coroutine library

在浏览器的客户端应用程序中?

【问题讨论】:

  • 就用它?不过,浏览器需要支持 ES6 生成器功能。如果没有,则需要使用转译器。

标签: javascript client-side coroutine co


【解决方案1】:

只是为了测试。请勿在生产中使用。

(function () {
    $.ajax({
        type: 'GET',
        url: 'https://raw.githubusercontent.com/tj/co/master/index.js',
        async: false,
    }).done(function (source) {
        var module = {exports: {}};
        var exports = module.exports;
        eval(source); // run the source of co
        window.co = module.exports; // bind co to window
        console.log(window.co);
    }).fail(function (xhr, textStatus, statusText) {
        console.log(textStatus, statusText);
    })
})();

【讨论】:

    【解决方案2】:

    当然可以,你需要转译你的代码(使用 babel 和 regenerator plugin ),它工作正常!

    【讨论】:

      猜你喜欢
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-04
      • 2016-05-06
      相关资源
      最近更新 更多