var sim = (function(){ var sim = {} sim.loaded = false sim.data = { carrierName: 'unknown', countryCode: 'us', mcc: '0', mnc: '0', } sim.fetch = function(cb){ sim.afterFetch = cb window.plugins.sim.getSimInfo(sim.success, sim.error) } sim.afterFetch = function(){} sim.success = function(data){ console.log(data) sim.data = data sim.data.countryCode = sim.data.countryCode.toLowerCase() // app is only available in US or Canada, so call the US API regardless if (sim.data.countryCode !== 'ca') { sim.data.countryCode = 'us' } sim.loaded = true sim.afterFetch() } sim.error = function(){ console.log("no SIM card detected") sim.afterFetch() } return sim })()