So, I am learning out backbone.js and are currently iterating over some models in a view with the below example. The first snippet works, when the other underscore.js-based one doesn’t. Why?
// 1: Working
this.collection.each(function(model){ console.log(model.get("description")); });
// 2: Not working
_.each(this.collection, function(model){ console.log(model.get("description")); });
What am I doing wrong, as I can’t see it by myself?
this.collectionis an instance whilethis.collection.eachis a method that iterates the proper object under the covers which is the.modelsproperty of a collection instance.With this said you can try:
Which is completely pointless as
this.collection.eachis a function that does similar to:So you might as well use
this.collection.each;P