Why bindall backbone




















Connect and share knowledge within a single location that is structured and easy to search. It's binding your functions to the right context, the context of your view. So you are sure you're not calling it by mistake in a different context. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Ask Question. In order to understand why bind method is needed first let's look at following example.

Above example is pretty straight forward. Notice that when we invoked says we invoked like this john. If we just want to get hold of the function that is returned by says then we need to do john. So the above code could be broken down to following code. Above code is similar to the code above it. All we have done is to store the function in a variable called func. If we invoke this function then we should get the alert message we expected.

However if we run this code then the alert message will be undefined rocks! We are getting undefined rocks! And window does not have any attribute called skill. Hence the output of this. Earlier we saw that using apply we can fix the problem arising out of this.

So lets try to use apply to fix it. I have searched in google and someone said that the method bindAll is necessary since if I switched my context, the calling of this. I feel confused on the "context". What it does is to automatically bind all its functions to its correct context. I personally think it was a convention for old version of Backbone.

Since new versions Backbone View automatically bind and unbind listeners in events. Find more by search Binding "this" here. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more.

Ask Question. Asked 8 years, 9 months ago. Related Questions. How to add a tooltip to the legend in google charts Check if a text is HTML or not JavaScript Intellisense in VS extremely slow and memory hungry Increment localStorage value by one How to display json data on ListView react native by post request api State is always outdated inside the promise resolve method Datatables.

How to loop through all rows and get id of each tr entry Htmlunit : An invalid or illegal selector was specified Why aren't these two bits of JavaScript equivalent? Creating this kind of popup in Firefox Addons?



0コメント

  • 1000 / 1000