var中的函数范围

时间:2015-12-23 15:40:47

标签: javascript angularjs promise angular-promise

我正在尝试访问函数createLocalAccount中的变量email和密码,我该如何维护代码结构呢?

var createLocalAccount = function(response) {
    return localDb.put('login', {
        uid: response.uid,
        email: email,
        password: password
    });
};

this.createAccount = function(firstName, lastName, email, password) {
    var deferred = $q.defer();
    createAccount(email, password)
        .then(createLocalAccount);
    return deferred.promise;
}

1 个答案:

答案 0 :(得分:1)

将其传递给函数:

move-to