私はちょうど JavaScript を学んでいるので、JavaScript の OOP は私の経験ではクラシック言語とは大きく異なるため、それを使用する練習をするために小さなおもちゃのアプリケーションを作成しています。エンジンをカプセル化したシングルトンにすることにしました。
私が聞きたかったのは、2 つのパブリック関数が何らかの形で依存している場合、このパターンを実行するためのより良い方法はありますか? オブジェクトリテラルを使用してパブリックインターフェイスを実装していたので、これを質問したかったのですが、残念ながら、これにより関数式がお互いを認識できなくなります。
または、この特定のパターンを完全に放棄して、別の方法でオブジェクトを実装する必要がありますか?
コードは次のとおりです。
function PKMNType_Engine(){
    "use strict";
    var effectivenessChart = 0;
    var typeNumbers = {
        none: 0,
        normal: 1,
        fighting: 2,
        flying: 3,
        poison: 4,
        ground: 5,
        rock: 6,
        bug: 7,
        ghost: 8,
        steel: 9,
        fire: 10,
        water: 11,
        grass: 12,
        electric: 13,
        psychic: 14,
        ice: 15,
        dragon: 16,
        dark: 17,
        fairy: 18
    };
    return {
        /**
         *Looks up the effectiveness relationship between two types.
         *
         *@param {string} defenseType 
         *@param {string} offenseType
         */
        PKMNTypes_getEffectivness: function(defenseType, offenseType){
            return 1;
        }
        /**
         *Calculates the effectiveness of an attack type against a Pokemon
         *
         *@param {string} type1 The first type of the defending Pokemon.
         *@param {string} type2 The second type of the defending Pokemon.
         *@param {string} offensiveType The type of the attack to be received.
         *@return {number} The effectiveness of the attack
         */
        PKMNTypes_getMatchup: function(type1, type2, offensiveType){
            var output = PKMNTypes_getEffectivness(type1, offensiveType) * PKMNTypes_getEffectivness(type2, offensiveType);
            return output;
        }
    };
}