I’m trying to get my head around the Todo sample app for Backbone.js
While I have most of it understood there is one part I don’t get and was hoping someone could explain for me.
Looking at https://github.com/jeromegn/localtodos/blob/master/javascripts/todos.js
Line 162: How does the “todo” parameter in the function get here? I can’t see how it’s sent or from where?
Any help would be much appreciated and yes I will credit good answers now I know how it works on this site.
Thanks
In the
AppView.initializemethod, on line 146, theaddOnemethod is registered as an event handler for theTodoscollection’s add event.When an item is added to the collection, Backbone triggers the
addevent, and passes the added model as the first argument to the event handler.According to the list of built-in events, the
addevent handler method is passed the following arguments:That means that the
addOnemethod could also receive two more arguments:But because in Javascript declaring the full argument list is not necessary, the authors of the sample has chosen only to “receive” the first argument.