我试图在承诺链的末尾返回一个对象:
var signUp = function(fb_ID,fb_accessToken) {
console.log("signup")
var TokenStorage = Parse.Object.extend("tokenStorage");
var restrictedAcl = new Parse.ACL();
var output = {}
var username;
var password;
return new Promise(function(resolve){
ExtendFacebookAccessToken(fb_accessToken).then(function(new_fb_accessToken){
restrictedAcl.setPublicReadAccess(false);
restrictedAcl.setPublicWriteAccess(false);
var user = new Parse.User();
// Generate a random username and password.
/*
var username = new Buffer(24);
var password = new Buffer(24);
_.times(24, function(i) {
username.set(i, _.random(0, 255));
password.set(i, _.random(0, 255));
});
*/
username = (Date.now().toString(36) + Math.random().toString(36).substr(2, 10)).toUpperCase();
password = (Date.now().toString(36) + Math.random().toString(36).substr(2, 10)).toUpperCase();
user.set("username", username.toString('base64'));
user.set("password", password.toString('base64'));
// Sign up the new User
return user.signUp().then(function(user) {
console.log('user:'+JSON.stringify(user))
// create a new TokenStorage object to store the user+GitHub association.
var ts = new TokenStorage();
ts.set('facebookID', fb_ID);
ts.set('fb_accessToken', new_fb_accessToken);
ts.set('username',username)
ts.set('password',password)
ts.set('user', user);
ts.setACL(restrictedAcl);
// Use the master key because TokenStorage objects should be protected.
return ts.save(null, { useMasterKey: true } );
}).then(function(tokenStorage) {
console.log('ggg:')
//var promise = new Parse.Promise();
output.username = username;
output.password = password;
output.process = "signup";
output.fb_accessToken = new_fb_accessToken;
output.success = true;
output.isnewuser = true;
//promise.resolve(output);
//return output
});
})
})
resolve(output)
}
'输出'当我使用'然后'来调用函数时,不返回对象: 注册(fb_ID,fb_accessToken)。然后(功能(数据){ 的console.log('数据&#39 + JSON.stringify(数据)) }) 数据对象不会在'输出' SignUp函数内的对象。有什么想法吗?