I wonder how I can pass a class property into function located in a .each of a method as below. I have found that I could call the property from the newly created instance but it means the class can't be replicated. Is there a object inheritance friendly way of calling the class property from inside a function located in function > .each > method > class?
class ok {
constructor() {
this.jojo = "first state";
}
myMethod() {
let rp = require('request-promise-native');
let cheerio = require('cheerio');
rp("https://tomydna.com")
.then(response => {
let $ = cheerio.load(response);
$('a').each(function() {
this.jojo = "second state"; // This does not work
ok1.jojo = "second state from outside"; // This would work but it is not good because it is related to one instance only. If a new Instance is created the method stops working.
console.log(ok1.jojo); // will replicate as many times it finds url on the page.
});
});
}
}
ok1 = new ok();
ok1.myMethod();