I believe your problem is that "this" may or may not refer to an instance of your collection, depending on whether you lost your binding (for example, if cpuTotal is passed as an argument in a function call). You can change the binding of the collection to the cpuTotal function in the initialize function. I have not tested this, but give it a try (kudos @Brian for recommendation to reduce):
window.ServerList = Backbone.Collection.extend({ model: Server, initialize: function() { _.bind(this.cpuTotal, this); // From Underscore.js }, cpuTotal: function(){ return this.reduce(function(memo, value) { return memo + value.get("cpu") }, 0); } });
erturne
source share