stolsky / the-smoking-mirror

GNU General Public License v3.0
0 stars 0 forks source link

optimize code #23

Open stolsky opened 2 years ago

stolsky commented 2 years ago

Bad code from BaseObject

example from line 105ff

    set currentState(id) {
        if (isNumber(id) && this.#states instanceof Array) {
            if (id === 0) {
                this.#current_state = null;
            } else {
                this.#current_state = this.#states.find((state) => state.id === id);
            }
        }
    }

better:

    setCurrentState(id) {
        if (isNumber(id) && this.#states instanceof Array) {
                this.#current_state = this.#states.find((state) => state.id === id) ?? null;
        }
       return this;
    }