使用.map()函数

时间:2015-04-21 13:49:54

标签: javascript function protractor

我有这个JS:

var getAccountNumberArray =  element.all(by.repeater('currentUserAccount in currentUserAccounts').column('currentUserAccount.accountNumber')).map(function (accounts) {
                return accounts.getText();
            });

            getAccountNumberArray.then(function (textArr) {
            console.log(textArr);
        });
    });

效果很好,但是我希望将它放在一个函数中,以便在我喜欢的时候调用,

MyAccountsPage.prototype.getAccountNumberArray = function () {
    element.all(by.repeater('currentUserAccount in currentUserAccounts').column('currentUserAccount.accountNumber')).map(function (accounts){
        return accounts.getText();
        });
};

为什么此函数会返回undefined

2 个答案:

答案 0 :(得分:1)

从函数返回结果

MyAccountsPage.prototype.getAccountNumberArray = function() {
    return element.all(by.repeater('currentUserAccount in currentUserAccounts').column('currentUserAccount.accountNumber')).map(function(accounts) {
        return accounts.getText();
    });
};

答案 1 :(得分:0)

MyAccountsPage.prototype.getAccountNumberArray = function () {
    return element.all(by.repeater('currentUserAccount in currentUserAccounts').column('currentUserAccount.accountNumber')).map(function (accounts){
        return accounts.getText();
        });
};

您需要返回它 - 没有显式return语句的函数返回undefined