問題
多少の変更を加えるだけで、複数のプロジェクトで使用できるJSLがあります。また、保守を容易にするために1つのコピーを残しておくことをお勧めします。
溶液
別のファイルを使用してそれをメインプログラムに組み込みます。名前空間を使用して、変数を他のモジュールから分離します。メインプログラムがカスタマイズを追加できるように名前空間を構築します。
// "example.jsl" reusable, extensible module
example = New Namespace( "example" ); // namespace to hold the reusable code
example:aaa = 1; // a variable in the namespace
// this represents the extensible part of the module
example:uuu = Function( {p}, Return( p ) ); // no transform by default
// this represents the reusable part of the module
example:fff = Function( {p}, // do something amazing
example:aaa += 1;
Return( example:uuu( p ) * example:aaa );
);
// "mainprog.jsl" uses the example code, and extends it
Include( "example.jsl" );
// this function replaces the default
example:uuu = Function( {p},
Return( Sqrt( p ) )
);
// use the amazing code from the package
p = example:fff( 16 );
q = example:fff( 9 );
r = example:fff( 4 );
Show( p, q, r );
討論
あなたが追加することがあります例:init(パラメータ) 一回限りの設定をするためにインクルードの後に呼び出す関数。または、パラメータがない場合は、example.jslファイルで一度だけ設定できます。
参照
スクリプトインデックスは、いくつかの追加パラメータを説明しています。