문제
사소한 변경 사항이있는 둘 이상의 프로젝트에서 사용할 수있는 JSL이 있으며 유지 보수를 쉽게하기 위해 하나의 복사본을 유지하려고합니다.
해결책
별도의 파일을 사용하여 주 프로그램에 포함하십시오. 변수를 다른 모듈과 분리하여 유지하려면 네임 스페이스를 사용하십시오. 주 프로그램이 사용자 지정을 추가 할 수 있도록 네임 스페이스를 작성하십시오.
// "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 파일에서 한 번 설정을 수행 할 수 있습니다.
참고 사항
스크립팅 인덱스는 몇 가지 추가 매개 변수를 설명합니다.