Skip to content

Instantly share code, notes, and snippets.

@michael-benin-CN
Created February 25, 2014 16:56
Show Gist options
  • Save michael-benin-CN/9212981 to your computer and use it in GitHub Desktop.
Save michael-benin-CN/9212981 to your computer and use it in GitHub Desktop.
This is an example of bind vs self scoping. Which do you prefer?
init: function () {
setInterval(function () {
ajax('/last-modified', {
cache: false
}).then(function (data) {
if (moment(this.get('date')).isBefore(data.modified)) {
this.set('appUpdated', true);
}
}.bind(this), function (e) {
//console.log(e);
}.bind(this));
}.bind(this), (this.get('seconds') * 1000));
}
init: function () {
var self = this;
setInterval(function () {
ajax('/last-modified', {
cache: false
}).then(function (data) {
if (moment(self.get('date')).isBefore(data.modified)) {
self.set('appUpdated', true);
}
}, function (e) {
//console.log(e);
});
}, (self.get('seconds') * 1000));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment