I'm trying to pass this
context within this chaining without any 'hacks' - I just want to use apply, call or bind (description is below):
var ArticlesCollection = Backbone.Collection.extend({
model: ArticleModel,
parse : function(response) {
var dateSinceFormatter = this.dateSinceFormatter; // right now solution
return _.chain(response)
.map(function(response) {
if(!_.difference(["id", "title", "link", "source", "image"], _.keys(response)).length) {
return {
id : (!response.id ? _.uniqueId() : response.id),
title : response.title,
content : response.preamble,
thumbnailUrl : ((!response.image) ? '' : response.image.url),
linkUrl: response.link,
timeAgo : '',
categoryName: '',
persistentUrl: response.link,
commentsEnabled: false
};
} else {
return {
id : response.id,
title : response.title,
content : response.preamble,
thumbnailUrl : response.thumbnail.url,
linkUrl: response.url,
timeAgo : dateSinceFormatter(response.published.datetime, response.published.niceformat), // I want to use this.dateSinceFormatter
categoryName: response.mainCategory,
persistentUrl: response.persistentUrl,
commentsEnabled: response.hasComments
};
}
})
.value();
}
});
any thoughts?