1
How to resolve the conflict between the this
of a jQuery loop performed within a javascript class method (ECMA6)?
Example, the metodoUm
loops using jQuery and for each loop iteration, calls the metodoDois
passing the object of interaction as a parameter, so there are two this
, one referring to the class Teste
, and another referencing the element found in each iteration of the method .each
.
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 resolve, or circumvent, this conflict?
Thanks for your help.
@Samir Braga, Thanks for the help, indicating to use $(this), but is presenting the error: Typeerror: this.methodDois is not a Function(...).
– Allan Andrade