我正在尝试使用显示模块模式来确定我页面上的 JavaScript 范围,这样我就不会污染全局命名空间。
<script type="text/javascript">
var myModule = (function(){
function windowLoad() {
// window onLoad things
return;
}
function otherFunc(){
// otherFunc things
}
window.onload = windowLoad;
return { otherFunc: otherFunc };
})();
myModule.otherFunc(); // myModule is undefined here
</script>
出于某种原因,如上面的评论所示,myModule
当我去使用它时是未定义的。为什么?