使用蓝鸟承诺

我有我的人的function,在它内部调用这样的承诺函数

var myPeople = function(){ var go; return new Promise (function(resolve){ User .getPeople() .then(function(allPeople){ go = allPeople; //console.log(go) resolve(go); }) }) return go; } 

如果我login我的去块内我得到我的对象,但我不能得到它返回此对象..

连锁诺言,也是 – 避免then(success, fail)反面模式:

 var myPeople = function(){ return User.getPeople() .then(function(allPeople){ // console.log(allPeople); return allPeople.doSomething(); // filter or do whatever you need in // order to get myPeople out of // allPeople and return it }); }); } 

然后在外面:

 myPeople.then(function(people){ console.log(people); // this will log myPeople, which you returned in the `then` });