桜を見ながら飲み食いしたいminamiです。 前回に引き続きJavaScriptで書くデザインパターンです。今回はシングルトンパターンについて調べてみました。 なぜ使うの? シングルトン(Singleton)パターンは、以下のような特徴があります。 あるクラスのインスタンスを一つだけにする つまり同じクラスを使って新しいオブジェクトを再度作成すると、最初に作ったオブジェクトの参照になる。 作られたオブジェクトへのグローバルなアクセス方法を提供する 機能の重複する新規のインスタンスを作ることなく、一つのオブジェクトを使いまわすことができるのでリソースを無駄にしません。また、インスタンスを一つだけにすることでグローバルな関数や変数を無駄に増やすことがなくなるので競合の危険をなくします。このあたりは前回のモジュールパターンの考え方と同様です。 簡単な書き方 var Single = { myNa
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く