我相信您遇到的问题是您没有在正在加载的页面中引用脚本文件,或者您没有将commonFunctions
对象包装在函数中。
我试过这个:script.js
(function () {
WinJS.Namespace.define("CommonObject", {
auth: function () {
return true;
}
});
}());
默认.js
app.addEventListener("activated", function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// TODO: This application has been newly launched. Initialize
// your application here.
} else {
// TODO: This application has been reactivated from suspension.
// Restore application state here.
}
if (app.sessionState.history) {
nav.history = app.sessionState.history;
}
args.setPromise(WinJS.UI.processAll().then(function () {
var test = CommonObject.auth(); // Comes out true and no exceptions
if (nav.location) {
nav.history.current.initialPlaceholder = true;
return nav.navigate(nav.location, nav.state);
} else {
return nav.navigate(Application.navigator.home);
}
}));
}
});
默认.html
<script src="/js/script.js"></script>