小编Sal*_*rni的帖子

Javascript - 代码不会停止在那时

我正在努力扩展我的知识(初学者阶段).基本上,我想使用promises向我的用户写新的电子邮件.我在我的游戏项目中有一些代码库,但我的功能并没有停止.这是应该写入数据库的函数:

changeEmailAddress(user, newEmail) {
       new Promise((resolve, reject) => {
            user.setEmail(newEmail);
            userRepository.saveUser(user).then(() => {
                return resolve();
            }).catch(e => {
                return reject(e);
            });
        }
    );
}
Run Code Online (Sandbox Code Playgroud)

如果我没有弄错的话,我应该如何使用它:

changeEmailAddress(user, "hello@there.com").then(function () {

    //it never comes in here :(
})
Run Code Online (Sandbox Code Playgroud)

我有类似的功能在用户工作,但我的功能是没有进入'然后'

javascript promise

2
推荐指数
1
解决办法
75
查看次数

标签 统计

javascript ×1

promise ×1