Wednesday 31 May 2017

Function returning undefined when loaded with require

I'm loading a script with require as follows:

const mPreferences = require('./scripts/da/local/preferences');

The script does get loaded. This is what preferences.js looks like:

var ROOTNS = ROOTNS || {};
ROOTNS.da = {}

ROOTNS.da.preferences = function(){
    function getLang(){
        return "english";
    }

    return {
        getLanguage: getLang
    }
};

However, when I go to access the function getLanguage, I get the response "undefined":

var lang = mPreferences.getLanguage;

So what's going on? Why is this returning undefined?



via AndroidDev

No comments:

Post a Comment