これは私のブートストラップです:
LanesBoard2010 = (function () {
var appRoot = this;
appRoot.deferredLoad = new Object(); //holding jqxhr states
appRoot.utils = {}; //namespace for helper classes
appRoot.models = {};
appRoot.data = (function () { } ()); //store data from webservices here
appRoot.app = (function () { } ()); //ViewModel
}();
いくつかの初期化の後、遅延アプリローダーを実行します。
function appStart() {
appRoot.deferredLoad.app = $.getScript('../TaskBoardContent/Script/app/lanesboard.js');
$.when.apply($, appRoot.deferredLoad.app).then(function () {
if (window.console)
if (debug)
console.log('application lanesdashboard was loaded successfully\n');
}, function () {
if (window.console)
if (debug)
console.log('fatal error: unable to load application lanesdashboard\n');
});
};
次に、appRoot にアクセスする必要があります。より一般的には、LanesBoard2010 のプロパティを変更する必要があります。
次のステートメントは、私のlanesboard.jsからのものです。両方の変数名が不明であることを確認できるため、最初の console.log の後で失敗します。
(function () {
if (window.console)
if (true) {
console.log('App has been initialised successfully');
console.log('Status of app access 1: ' + appRoot);
console.log('Status of app access 2: ' + LanesBoard2010);
}
}());
ばかげているように聞こえるかもしれませんが、変数に安全にアクセスするにはどうすればよいですか? ベストプラクティスはありますか? これをどのように行いますか?