5

I'm learning Backbone and had some issues with the on()-function. But actually it's a very basic JavaScript question.

Why is it that the first line of code below works, and the second doesn't? Using the second line, the render-function is never triggered. Mind the brackets.

Works

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

Fails

this.collection.on( 'reset', this.render(), this );
ndequeker
  • 7,932
  • 7
  • 61
  • 93
  • 1
    possible duplicate of [What's the meaning of "()" in a function call?](http://stackoverflow.com/questions/3641330/whats-the-meaning-of-in-a-function-call) – pimvdb Jun 30 '12 at 14:01

1 Answers1

9

this.render() executes function (so in your case you are passing data returned from this function), whereas this.render is handler to function.

Zbigniew
  • 27,184
  • 6
  • 59
  • 66