aboutsummaryrefslogtreecommitdiff
path: root/files/ja/code_snippets/modules/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/ja/code_snippets/modules/index.html')
-rw-r--r--files/ja/code_snippets/modules/index.html32
1 files changed, 32 insertions, 0 deletions
diff --git a/files/ja/code_snippets/modules/index.html b/files/ja/code_snippets/modules/index.html
new file mode 100644
index 0000000000..46b808913a
--- /dev/null
+++ b/files/ja/code_snippets/modules/index.html
@@ -0,0 +1,32 @@
+---
+title: モジュール
+slug: Code_snippets/Modules
+translation_of: Archive/Add-ons/Code_snippets/Modules
+---
+<p>単純なコードで <a href="/ja/JavaScript_code_modules" title="ja/JavaScript code modules">JavaScript モジュール</a> を Mozilla 固有でないコードにします (ブラウザにポーティングする場合など)。eval() は、ユーザの入力に依存しない <code>EXPORTED_SYMBOLS</code> 配列上でのみ使用されるため心配いりません。</p>
+<pre class="brush: js">function importModule (thatObj) {
+ thatObj = thatObj || window;
+
+ var EXPORTED_SYMBOLS = [
+ // シンボルをここに置く
+ ];
+
+ // ここにコードを書く...
+
+ // コードの終わりに: ('i' や 'thatObj' はエクスポートされません!)
+ for (var i=0; i &lt; EXPORTED_SYMBOLS.length; i++) {thatObj[EXPORTED_SYMBOLS[i]] = eval(EXPORTED_SYMBOLS[i]);}
+}
+</pre>
+<p>あるいは、モジュールを一度だけ使用する場合:</p>
+<pre class="brush: js">(function (thatObj) {
+ thatObj = thatObj || window;
+
+ var EXPORTED_SYMBOLS = [
+ // シンボルをここに置く
+ ];
+
+ // ここにコードを書く...
+
+ // コードの終わりに: ('i' や 'thatObj' はエクスポートされません!)
+ for (var i=0; i &lt; EXPORTED_SYMBOLS.length; i++) {thatObj[EXPORTED_SYMBOLS[i]] = eval(EXPORTED_SYMBOLS[i]);}
+})(); // オブジェクトの引数をここに置けます</pre>