-
-
Save waleedshkt/c3bededf875aa4e7c7a77cedc1313304 to your computer and use it in GitHub Desktop.
Resolving a promise within iife?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
})); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
results = require('./myiife'); | |
console.log(results.instance.apromiseresolved) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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