I'm rather beginning in JavaScript/jQuery, so pardon my question if it feels too basic.
I have class with two (or more) methods, one calls another inside it inside jQuery $.each()
loop.
class X {
method_a (array){
$.each(array, function(index, item){
this.method_b(item);
});
}
method_b (item) {
// do something with item
}
}
But this throws TypeError, that method_b is not a function, since this
refers to the item
instead of this object. Is there any other way properly call this
inside a jQuery $.each() or the only way is to make a variable let obj = this;
and call it a day?
Am I missing something? Maybe something with methods' declaration? Any help would be appreciated.