backbone.js 的目的是什么? [英] What is the purpose of backbone.js?

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

问题描述

我试图从它的网站 http://documentcloud.github.com/backbone 了解backbone.js 的效用,但我还是想不通.

I tried to understand the utility of backbone.js from its site http://documentcloud.github.com/backbone, but I still couldn't figure out much.

谁能帮助我解释它的工作原理以及它如何帮助我编写更好的 JavaScript?

Can anybody help me by explaining how it works and how could it be helpful in writing better JavaScript?

推荐答案

Backbone.js 基本上是一个超级轻量级​​的框架,它允许您在 MVC(模型、视图、控制器)时尚在哪里...

Backbone.js is basically an uber-light framework that allows you to structure your Javascript code in an MVC (Model, View, Controller) fashion where...

模型是检索和填充数据的代码的一部分,

Model is part of your code that retrieves and populates the data,

View 是这个模型的 HTML 表示(视图随着模型的变化而变化等)

View is the HTML representation of this model (views change as models change, etc.)

和可选的 Controller 在这种情况下允许您通过 hashbang URL 保存 Javascript 应用程序的状态,例如:http://twitter.com/#search?q=backbone.js

and optional Controller that in this case allows you to save the state of your Javascript application via a hashbang URL, for example: http://twitter.com/#search?q=backbone.js

我在 Backbone 中发现的一些优点:

Some pros that I discovered with Backbone:

  • 不再是 Javascript Spaghetti:代码被组织并分解成具有语义意义的 .js 文件,这些文件随后使用 JAMMIT 进行组合

  • No more Javascript Spaghetti: code is organized and broken down into semantically meaningful .js files which are later combined using JAMMIT

不再需要jQuery.data(bla, bla):无需将数据存储在 DOM 中,而是将数据存储在模型中

No more jQuery.data(bla, bla): no need to store data in DOM, store data in models instead

事件绑定正常

非常有用的 Underscore 实用程序库

extremely useful Underscore utility library

backbone.js 代码文档齐全,值得一读.让我对一些 JS 代码技术大开眼界.

backbone.js code is well documented and a great read. Opened my eyes to a number of JS code techniques.

缺点:

  • 我花了一些时间来理解它并弄清楚如何将它应用到我的代码中,但我是 Javascript 新手.

这里有一组关于使用 Backbone 和 Rails 作为后端的很棒的教程:

Here is a set of great tutorials on using Backbone with Rails as the back-end:

CloudEdit:使用 Rails 的 Backbone.js 教程:

http://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by-example/

http://www.jamesyu.org/2011/02/09/backbone.js-tutorial-with-rails-part-2/

附言还有这个很棒的 Collection 类,它可以让您处理模型集合并模拟嵌套模型,但我不想从一开始就让您感到困惑.

p.s. There is also this wonderful Collection class that lets you deal with collections of models and mimic nested models, but I don't want to confuse you from the start.

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

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