why do bindAll in backbone.js views?

后端 未结 3 1691
面向向阳花
面向向阳花 2020-12-04 09:36

In backbone\'s todo demo the code has a few spots where _.bindAll(this,...) is used. Specifically it\'s used in the initialize function of both vie

3条回答
  •  暖寄归人
    2020-12-04 09:53

    this.$ limits jQuery's context to the view's element, so operations are quicker.

    Additionaly, this.$('.todo-item') won't find your elements with todo-item class outside your view's element.

提交回复
热议问题