You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is actually not a design pattern from Gang of Four, neither one from P of EAA. This is a traditional JavaScript pattern, which main goal is to provide encapsulation and privacy.
963
+
これは実際にはGang of FourやP of EAAのデザイン・パターンではありません。これはカプセル化とプライバシーを目的とした伝統的なJavaScriptのパターンです。
964
964
965
-
Using the module pattern you can achieve privacy based on the JavaScript's functional lexical scope. Each module may have zero or more private members, which are hidden in the local scope of a function. This function returns an object, which exports the public API of the given module:
In the example above we have IIFE (Immediately-Invoked Function Expression), which after being called returns an object, with two methods (`setTitle`and`getTitle`). The returned object is being assigned to the `Page`variable.
988
+
上記の例は2つのメソッド( `setTitle`と`getTitle` )を持ったオブジェクトを返すIIFE(Immediately-Invoked Function Expression)を持っています。返却されたオブジェクトは、 `Page`変数に関連付けられています。
989
989
990
-
In this case the user of the `Page`object doesn't has direct access to the `title`variable, which is defined inside the local scope of the IIFE.
Once we want to inject `foo` inside any other component we won't be able to use the private methods, but only the public ones. This solution is extremely powerful especially when one is building a reusable library.
0 commit comments