Since from co@4.0+
we can use below statement
var fn = co.wrap(fn*)
to convert a generator into a regular function that returns a Promise.
Then I face a problem
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;
how to create a instance in b.js
by co
.
@Bergi said it`s a bad practice
then I want to ask anthor question
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 }
is it a bad practice ?