I can access an attribute of the class within the scope of the constructor, however outside gives ' undefined '
constructor(errorAlert){
this._errorAlert = errorAlert;
}
If, for example, in the code above, I give% of the% in the parameter received and the attribute, both return the same value, but when I use the attribute in the rest of the class, I can not.
class Controller{
constructor(errorAlert){
this._errorAlert = errorAlert;
}
login(login, senha){
let $ = new Serv();
$.ajax({
'url': '/login',
'type': 'post',
'responseType': 'json',
'data': 'login='+login+'&senha='+senha
}).then(function(resolve){
let datas = resolve;
if(datas['loginStatus'] == 1){
window.location = base_url;
}else{
console.log(this._erroAlert);
view.viewErrorMessage("Usuário ou senha incorreto", this._errorAlert);
}
}).catch(function(reject){
console.log(reject);
});
}
}
The code works perfectly, my only problem is that of the scope of the same attribute.
Error:
TypeError: Cannot read property '_erroAlert' of undefined at Controller.js:19 at <anonymous>