I saw a problem, probably this is what it looks like.
The code copy is as follows:
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. This javascript is generated when called and is related to the context. This is how to solve it. I tested it and used call.
The code copy is as follows:
setTimeout.call(foo(), f.say, 500)
Some solutions online
This pointing problem with setTimeout in js
Using Timer in JavaScript
In the end, it is actually a question of understanding this.
One day I understand it and continue writing