Javascript 在浏览器中使用协同程序库客户端?
我如何使用Javascript 在浏览器中使用协同程序库客户端?,javascript,client-side,coroutine,co,Javascript,Client Side,Coroutine,Co,我如何使用 在浏览器的客户端应用程序中?仅用于测试。不要在生产中使用 (function () { $.ajax({ type: 'GET', url: 'https://raw.githubusercontent.com/tj/co/master/index.js', async: false, }).done(function (source) { var module = {exports: {}};
在浏览器的客户端应用程序中?仅用于测试。不要在生产中使用
(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);
})
})();
只是为了测试。不要在生产中使用
(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);
})
})();
当然可以,您需要传输您的代码(使用babel with the),而且它工作得很好 当然可以,您需要传输您的代码(使用babel with the),而且工作正常 就用它?不过,浏览器需要支持ES6生成器功能。如果没有,你需要用一个传送机。就用它吧?不过,浏览器需要支持ES6生成器功能。如果没有,你需要使用一个传送机。