Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
uupaa edited this pageOct 24, 2015 ·7 revisions

MyExample.js モジュールのソースコードは、lib/MyExample.js にあります。このファイルに必要な機能を実装していきます。

Module has two code blocks

lib/MyExample.js は、
function moduleExporter() { ... }
function moduleClosure() { ... } の2つの関数から構成されています。

詳細な説明はWebModule Idiom を参照してください。

lib/MyExample.js のfunction moduleExporter() { ... }は、モジュールを global 空間に export し、node で require("MyExample") を出来るようにするための定形的なコードです。

(functionmoduleExporter(name,closure){"use strict";varentity=GLOBAL["WebModule"]["exports"](name,closure);if(typeofmodule!=="undefined"){module["exports"]=entity;}returnentity;})("MyExample",functionmoduleClosure(global){    :    :returnMyExample;// return entity});
  • モジュールを global 空間に export する処理は、webModule.exports 側で行われます
  • 通常は moduleExporter の内部に手をいれる必要はありません
  • function moduleClosure() { ... } がモジュールのクロージャに相当します。
  • function MyExample() { ... }class MyExamle に相当します。

MyExample は MyExample.prototype.concat メソッドを持つシンプルなモジュールです。

最後から2行目でreturn MyExample; を行い、モジュールの実体(moduleEntity) を返しています。

(functionmoduleExporter(name,closure){    :    :})("MyExample",functionmoduleClosure(global){"use strict";// --- dependency modules ----------------------------------// --- define / local variables ----------------------------// --- class / interfaces ----------------------------------functionMyExample(value){//@arg String = "" - commentthis._value=value||"";}MyExample["repository"]="https://github.com/uupaa/MyExample.js";// GitHub repository URL.MyExample["prototype"]=Object.create(MyExample,{"constructor":{"value":MyExample},// new MyExample(value:String = ""):MyExample"concat":{"value":MyExample_concat},// MyExample#concat(a:String):String});// --- implements ------------------------------------------functionMyExample_concat(a){//@arg String//@ret Stringreturnthis._value+a;}returnMyExample;// return entity});
Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp