js 创建全局变量

(function (EPC) {
var commonUtl = EPC.commonUtl;
var Pagecommon = EPC.Pagecommon;
var epcTemplateUrl = './templates/epcsearch/EPC.vue'
var EpcCmp = {
template : commonUtl.getTemplate(epcTemplateUrl),
components:{
'epc-header': EPC.EpcseachHeaderCmp,
'epc-menubar': EPC.MenuBarCmp
},
created:function(){
EPC.orderNum = this.$route.params.orderNum;
Pagecommon.retitle('tis_page_epcsearch');
}
};
EPC.EpcCmp = EpcCmp;
})((window.EPC = window.EPC||{}));

好处:闭包,成为没用的东西成为局部变量

等价于
var EPC = window.EPC ||{};
var EpcCmp = {
template : commonUtl.getTemplate(epcTemplateUrl),
components:{
'epc-header': EPC.EpcseachHeaderCmp,
'epc-menubar': EPC.MenuBarCmp
},
created:function(){
EPC.orderNum = this.$route.params.orderNum;
Pagecommon.retitle('tis_page_epcsearch');
}
EPC.EpcCmp = EpcCmp;

你可能感兴趣的:(js 创建全局变量)