nswbmw / N-club

使用 Koa + MongoDB + Redis 搭建论坛系统
517 stars 107 forks source link

关于generator的问题 #2

Open quoniammm opened 9 years ago

quoniammm commented 9 years ago
var userExist = yield $User.getUserByName(data.name);
if(userExist) {
//......
}

yield不是没有返回值的吗?下面这个程序a的值也没打印出来,为什么上面的程序,userExist会被赋值呢

> function *con() {
... var a = yield function() {
..... return 1;
..... }
... console.log(a);
... console.log('b');
... }
undefined
> con()
{}
> var a = con()
undefined
> a.next()
{ value: [Function], done: false }
> a.next()
undefined
b
{ value: undefined, done: true }
nswbmw commented 9 years ago

你可以去了解下 co