0

因为co@4.0+我们可以使用下面的语句

var fn = co.wrap(fn*)

将生成器转换为返回 Promise 的常规函数​​。

然后我面临一个问题

a.js

var F = function *(a,b,c){
    this.a = yield this.getA(a);
    this.b = yield this.getB(b);
    this.c = yield this.getC(c);
}

F.prototype.getA = function * (a){
    //........
}
F.prototype.getB = function * (b){
    //........
}
F.prototype.getC = function * (c){
    //........
}
exports.F = F;

b.js如何在by中创建实例co


@Bergi 说这是一种不好的做法

然后我想问一个问题

function* F(){
  yield this.x = 2;
  yield this.y = 3;
}
var obj = {};
var f = F.bind(obj)();

f.next();
f.next();
f.next();

console.log(obj);
// { x: 2, y: 3 }

这是不好的做法吗?

4

0 回答 0