How do I resolve the conflict between this
of a jQuery loop performed within a method of a class in javascript (ECMA6)?
Example, metodoUm
loops using jQuery and for each iteration of the loop, calls metodoDois
passing the interaction object as a parameter, so there are two this
, one referring to class Teste
and another reference to the element found in each iteration of the .each
method.
class Teste{
metodoUm(){
$('input').each(function () {
// $(this) adicionado para referenciar o jQuery
this.metodoDois($(this));
});
}
metodoDois(t){
console.log(t);
}
}
teste = new Teste();
teste.metodoUm();
Error presented:
TypeError: this.metodoDois is not a function(...).
How to solve, or get around, this conflict?
Thanks in advance for your help.