0
\$\begingroup\$

Does exist a cleaner way to call a static method inside ES6 Array.filter function ?

mine(input = '') {
    var translatedAnswers = this.constructor.translate(this._defaultAnswers);
    var self = this;
    return translatedAnswers.filter(function (answer) {
        return self.constructor.match(input, answer);
    });
}
\$\endgroup\$
2
\$\begingroup\$

With an arrow function I can avoid the var self = this;

mine(input = '') {
    const translatedAnswers = this.constructor._translate(this._defaultAnswers);
    return translatedAnswers.filter(answer => this.constructor._match(input, answer));
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.