I'm curious about the difference between these two AngularJS services. Both involve promises and essentially both work.
Method using a self variable:
module.exports = function () {
var self = this,
data = false;
self.someFunction = function () {
methodFromAnotherService().then(function (reponse) {
data = response;
});
};
};
Method using binding:
module.exports = function () {
var data = false;
this.someFunction = function () {
methodFromAnotherService().then(function (reponse) {
data = response;
}.bind(this));
};
};
The second one only works with binding. I understand that this is related to scope. Please share any useful insights on the major differences.