私のライブラリのほとんどのセクションは、次のような構造を持つファイルで構成されています。
myLib.Something = (function() {
function Something() {
}
return Something;
})();
今、私のファイルが次のようになっているSomething
とします。document
window
myLib.Something = (function() {
function Something(id) {
this.somethingElse = document.getElementById(id);
}
return Something;
})();
のコンストラクター内でドキュメントを使用する場合、ドキュメントSomething
をIIFEに渡して、以下のようにする必要があります。
myLib.Something = (function(document) {
function Something(id) {
this.somethingElse = document.getElementById(id);
}
return Something;
})(document);
または、IIFE 以外で変数を使用する場合にのみ変数を渡す必要がありSomething
ますか? 以下のように、
myLib.Something = (function(document) {
var document = document;
function Something() {
}
return Something;
})(document);