I am wondering what is difference between those two services in AngularJS. In both there is promise and basicly both works.
Method with self variable:
module.exports = function () {
var self = this,
data = false;
self.someFunction = function () {
methodFromAnotherService().then(function (reponse) {
data = response;
});
};
};
Method with binding:
module.exports = function () {
var data = false;
this.someFunction = function () {
methodFromAnotherService().then(function (reponse) {
data = response;
}.bind(this));
};
};
The secound one doesn't work without binding. I know that this have something to do with scope. Please provide any usefull information about major differences.