javascript - How can methods in ES6 modules call each other?
phpcn_u1582
phpcn_u1582 2017-05-19 10:39:01
0
2
446

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()来进行非空判断,该怎么调用???
    },
}
phpcn_u1582
phpcn_u1582

reply all(2)
滿天的星座

Treat it as an object, use this

过去多啦不再A梦
  • 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'

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template