javascript - Anybody can help me analyze these code the backbone each function meanings? -


now , can assume app.todos collection. assume had trigger filterall function .

filterone : function (todo) {   console.log(todo);   todo.trigger('visible'); },   filterall : function () {   console.log(app.todos);   app.todos.each(this.filterone, this); }, 

after had read underscore doc each , each_.each(list, iterator, [context]) , iterates on list of elements, yielding each in turn iterator function.

but filterall function use each iterator function this.filterone ? what's meaning ? filterone not list elements , please me .

thanks

from underscore documentation see _.each follows

_.each(list, iterator, [context])  

here list can correspond models.

so can written

                       `app.todos.each(function() { } , this);`                                        **or**                         _.each(app.todos.models, function() { } , this); 

so equivalent

app.todos.each(function(todo) {      console.log(todo);      todo.trigger('visible'); }, this); 

or

_.each(app.todos.models, function(todo) {          console.log(todo);          todo.trigger('visible');  }, this); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -