I saw a problem that probably looked like this.
name = 'out of you'
foo = function(){
this.name = 'xxoo';
}
foo.prototype.say = function(){
console.log(this.name);
}
f = new foo();
f.say(); // This sentence will output xxoo
setTimeout(f.say, 500); // This sentence will output out of you
This is a pitfall. JavaScript's this is generated when it is called, and it is also related to the context. This is how to solve it. I tested it and used call.
setTimeout.call(foo(), f.say, 500)
Some solutions on the Internet
This points to the problem of setTimeout in js
Using Timer in JavaScript In the end, it’s still a matter of understanding this.
I can continue writing when I understand it better one day