How to... make "Input.isPressed" use "_gamepadsStates[n]"?

Ok so this thread is partially related to this one (about the use of multiple gamepads): simply put, I'm trying to solve it myself editing "Input.isPressed".
Here's the original code:
Code:
/**
 * Checks whether a key is currently pressed down.
 *
 * @static
 * @method isPressed
 * @param {String} keyName The mapped name of the key
 * @return {Boolean} True if the key is pressed
 */
Input.isPressed = function(keyName) {
    if (this._isEscapeCompatible(keyName) && this.isPressed('escape')) {
        return true;
    } else {
        return this._currentState[keyName];
    }
};
Here's mine:
Code:
Input.isPressed = function(keyName, gamepadNumber) {
    if (this._isEscapeCompatible(keyName) && this.isPressed('escape')) {
        return true;
    } else if (gamepadNumber == undefined) {
        return this._currentState[keyName];
    } else {
        return this._gamepadStates[gamepadNumber][keyName];
    }
};
When I test my project, it doesn't crash, but it works only when the "else if" condition is true; when the condition is false, it doesn't crash, it simply always returns false (since I'm using 4 gamepads, "gamepadNumber" is always between 0 and 3).

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-input-ispressed-use-_gamepadsstates-n.78971/