MZ Using setTimeOut not picking up variables?

I'm trying to use setTimeOut to do a countdown to change an actors face after a short period. It seems to work if I put in stuff that isn't a variable, for instance if the actor id is 1 - it will work for 1, when I try to make an actor name as a variable I'm greeted with this.
Hkfyg9I.png


This is the bit of the code that runs the script:
Code:
const performDamageFaceChange = Game_Actor.prototype.performDamage
Game_Actor.prototype.performDamage = function() {
    Game_Battler.prototype.performDamage.call(this);
    performDamageFaceChange.call(this)
    actor = this._actorId;
    name = (this._faceName + '' + 'Hurt');
    index = this._faceIndex;
    $gameActors.actor(actor).setFaceImage(name,index);
    setTimeout(this.revertFaceImage,500);
};

Game_Actor.prototype.revertFaceImage = function() {
   actor = this._actorId;
   name = (this._originalFaceName);
   index = this._originalFaceIndex;
   $gameActors.actor(actor).setFaceImage(name,index);
};

Not sure why it isn't picking them up when they're right inside it. Any help would be appreciated.
That's because the method is being called on a different scope. Try using an arrow function or binding it to the local object:

Code:
   setTimeout(() => this.revertFaceImage(), 500);

Code:
   setTimeout(this.revertFaceImage.bind(this),500);
The setTimeout function loses it's scope.

this no longer refers to the Game_Actor object, but to the timeout function, which doesn't have a name.

To get around this, you can change your function that calls the timeout to take the old face and all the other stuff you're pulling from 'this' as arguments. Or you can call the setTimeout from within the performDamage function instead.
That's because the method is being called on a different scope. Try using an arrow function or binding it to the local object:

Code:
   setTimeout(() => this.revertFaceImage(), 500);

This got it working. Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/using-settimeout-not-picking-up-variables.126807/