util/common.js
//定义一个ES6的模块,对外暴露很多公共的方法
export default {
isEmpty(obj){
for (var name in obj){
return false;
}
return true;
},
isEmptyStr(str){
if(str == null || str == undefined || str == ''){
return true;
}else{
return false;
}
},
initUser(){
//假设这里需要调用同模块中的isEmpty()来进行非空判断,该怎么调用???
},
}
过去多啦不再A梦2017-05-19 10:41:01
common.js
function isEmpty(obj){
for (var name in obj){
return false;
}
return true;
}
function initUser(){
isEmpty(obj)
...
}
export {isEmpty,initUser}
xxx.js
import {isEmpty,initUser} from './common'
And I feel like your common.js should be used as a universal script
Just do it directlyimport './common.js'