JQuery on (); function

I am learning Backbone and had some problems with the on () function. But this is actually a very simple JavaScript question.

Why does the first line of code below work and the second not? Using the second line, the rendering function never starts. Pay attention to the brackets.

Work

this.collection.on( 'reset', this.render, this );

Fails

this.collection.on( 'reset', this.render(), this );
+5
source share
1 answer

this.render()executes the function (therefore, in your case, you pass the data returned from this function), whereas it this.renderis a handler for the function.

+9
source

All Articles