为什么bindAll在Backbone.js的看法? [英] why do bindAll in backbone.js views?

查看:109
本文介绍了为什么bindAll在Backbone.js的看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在骨干待办事项演示的code的几个景点,其中 _。bindAll(这个......)。特别是它在用于初始化的两种观点功能。至于我可以告诉大家有必要做到以下几点:

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 views. As far as I can tell it's necessary to do the following:

this.$('.todo-content').text(content);

但有为什么要做到以上,当一个人可以这样做:

But why would one want to do the above, when one can do:

$('.todo-content').text(content);

推荐答案

这一点。$ 限制了jQuery的上下文视图的元素,所以操作速度更快。

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

Additionaly,这一点。$('。TODO项目')将无法找到待办事项项的内容视图的元素之外类。

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

这篇关于为什么bindAll在Backbone.js的看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆