You've cached the initMembers method in your oldMethod variable, but then appear to be making a new method called SpriteIdleUpdate. If that method is not called anywhere, then nothing will happen.
Also note your casing - SpriteIdleUpdate is a different method than spriteIdleUpdate.
Are you looking to add code to the initMembers method, or to an existing spriteIdleUpdate method, or make a new method called spriteIdleUpdate? The answer isn't clear from the code you've posted.
I doubt you want initMembers to be called every time an update function is called, so taking a guess that you want to add some code to initMembers, this snippet would be more appropriate:
Code:
const originalInitMembers = Sprite_Battler.prototype.initMembers;
Sprite_Battler.prototype.initMembers = function() {
this._idleEffect = 0;
originalInitMembers.call(this);
};
Here, the first line stores the current code of the initMembers method, unaltered. The next line then overwrites it, saying instead of doing what it originally did, do something else.
The first line of the replacement function sets the instance of the Sprite_Battler's _idleEffect property to 0. The second then calls the code from the original, unaltered function (which was stored on the first line of the snippet).
However, the stored function needs to be called with a special method available to all functions in JavaScript called "call". It accepts as its first argument the context to call the function with, then accepts arguments matching the function's parameters. Since initMembers doesn't have any parameters, we just need to pass in context.
Since we want originalInitMembers to be called with the same context as the instance of Sprite_Battler calling the new initMembers method, we can use the keyword "this" to pass it into call().
"this" and context in JavaScript doesn't work the same as it does in a lot of other languages and can be tricky to understand at first. Try reading up
MDN's article on this and on
the .call method.