Skip to content

Instantly share code, notes, and snippets.

@benneely
Created March 9, 2017 15:36
Show Gist options
  • Save benneely/1d1e648a457e4da2b1e87bffa7f892bf to your computer and use it in GitHub Desktop.
Save benneely/1d1e648a457e4da2b1e87bffa7f892bf to your computer and use it in GitHub Desktop.
Resolving a promise within iife?
/**
* Duke Data Service API.
* REST API to the Duke Data Service. Some requests require Authentication.
*
*/
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['axios'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('axios'));
}
}(this, function(axios) {
var exports = function() {
this.encodedAddress = encodeURIComponent('300 W. Morgan St Durham NC 27707');
this.results = this.getInfo();
};
exports.prototype.getInfo = function () {
return axios.get('https://api.github.com/users/benneely')
};
exports.instance = new exports();
return exports;
}));
results = require('./myiife');
console.log(results.instance.apromiseresolved)
/**
* Duke Data Service API.
* REST API to the Duke Data Service. Some requests require Authentication.
*
*/
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['aGetPromise'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('./aGetPromise'));
}
}(this, function(aGetPromise) {
var exports = function() {
this.apromiseresolved = aGetPromise.instance.results.then(function(response){
return response.data;
}).catch(function(err){
throw new Error(err);
})
this.datestarted = Date();
};
exports.instance = new exports();
return exports;
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment