2012-06-30 53 views
5

我学习骨干,并与上()有一些问题 - 功能。但实际上这是一个非常基础的JavaScript问题。jQuery on();功能

为什么是它的以下作品的第一行代码,第二个不? 使用第二行,渲染函数永远不会被触发。注意括号。

作品

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

失败

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

的可能重复[这是什么的“()”函数调用的含义是什么?(http://stackoverflow.com/questions/3641330/whats-the-meaning-of-in-a-function-call) – pimvdb

回答

9

this.render()执行功能(所以你的情况你逝去的数据从该函数返回),而this.render是处理程序的功能。

+0

因此使用this.render()它仅执行一次,当我结合功能? – Voles

+2

由'使()'函数返回的是,要传递的数据。 – Zbigniew