In file A, I am getting a promise inside a IIFE, and updating a variable. This variable is returned(exposed for other files).
var ServiceResponse = (function() {
var cardPattern = null;
getCardPattern().then(function(response) {
console.info('Successfully fetched card pattern details.');
cardPattern = response;
App.init();
},
function(error) {
console.error('Failed fetching card pattern details!');
});
return {
cardPattern : cardPattern
}
})();
In file B, I am trying to consume this returned variable but i am getting null and not the updated value from the promise response.
var validateCreditCard = function(cardNumber, expiryMonth, expiryYear, cvv) {
var creditCardPattern = ServiceResponse.cardPattern;
I am making sure that from file B invocation is done only after the promise is returned, but no luck. Why?