简体   繁体   中英

export namespace function is undefined

I have a namespace.

var ns = ns || {};
ns.test = function(){

    //stuff
    var f = function(){
    };

    return {f:f};

}

If i want to call f for example in main.js it says ns is undefined

If i change the code to this :

 var ns = ns || {};
export default ns.test = function(){

    //stuff
    var f = function(){
    };

    return {f:f};

}

The error is : Cannot read property 'f' of undefined

ns.test().f() will work for you.

var ns = ns || {};
ns.test = function(){
    //stuff
    var f = function(){
        console.log('f invoked');
    };

    return {f:f};
}

This should work for you:

var ns = ns || {};
export default ns.test = function(){

    f : function(){
  }


}

Call should be this way:

ns.test().f();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM