I wasn’t sure how to express my question in a way that would make it understandable, so I created a diagram below. The example is specific to JavaScript and Backbone.js, but I’m assuming this may also be regarded as just a general programming question as well.
I have an example of a Backbone collection and I’m having trouble understanding how the values are being passed around. I’m assuming that ‘task’ could just as easily be any arbitrary value like ‘taco’ or ‘horse’ and work just as well. I’m just wondering where and how ‘task’ is getting its value mapped to it.
Here is how I am looking at the problem and I’ve tried to recreate the path of my confusion below:

Here is the Task model if that helps:
var Task = Backbone.Model.extend({
isComplete: function() {
return this.get('completed_at') !== null;
}
});
The comparator function is called by underscore’s
_.sortBywith array element as an argument, there is a ton of object creating and iteration going on for what essentially comes down to much faster native sort:Or a simpler example:
The comparator function here gets its arguments from the sort function when it tries to resolve the sort order, the value that you return from the comparator determines in what order the array is sorted.
I’d suggest normal sort over the backbone sort, as it’s 10x faster for me in chrome and easier to understand because the comparator function actually… compares: http://jsperf.com/underscore-sort-vs-normal-sort