javascript 对 BackboneJS 和 ExpressJS 感到困惑
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6943899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Confused about BackboneJS and ExpressJS
提问by egidra
I want to create a NodeJS application, and I am learning more about the packages that need to be installed to make development easier. Two packages in particular, ExpressJS and BackboneJS, are confusing me. What is the difference between the two? Backbone provides an MVC structure, but doesn't ExpressJS deal with views and controllers, too? How should I use these two packages in conjunction with each other, or should I even use them in conjunction with each other?
我想创建一个 NodeJS 应用程序,我正在学习更多关于需要安装以使开发更容易的包。特别是两个包,ExpressJS 和 BackboneJS,让我很困惑。两者有什么区别?Backbone 提供了 MVC 结构,但是 ExpressJS 不处理视图和控制器吗?我应该如何将这两个包相互结合使用,或者我应该如何将它们相互结合使用?
Thanks!
谢谢!
回答by Mauvis Ledford
Backbone is a front-end framework. Express is a back-end framework.
Backbone 是一个前端框架。Express 是一个后端框架。
To further clarify, you could essentially run Backbone.js stand-alone with no backend support - just HTML, CSS, and JavaScript, and have "page switching" loading HTML templates through hash tag changes and load and save data through cookies or localStorage - but in the end your app needs to talk to a backend services for authenticating a user or saving / restoring data from a database, etc. That's where you'd want Express / node.js to comes in.
为了进一步澄清,您基本上可以在没有后端支持的情况下独立运行 Backbone.js - 只有 HTML、CSS 和 JavaScript,并通过哈希标签更改“页面切换”加载 HTML 模板,并通过 cookie 或 localStorage 加载和保存数据 -但最终您的应用程序需要与后端服务对话以验证用户或从数据库中保存/恢复数据等。这就是您希望 Express / node.js 进来的地方。
You could also do all this stuff without Backbone and just Express (or another backend language / framework), but then all your pages are separate requests to the server (unless you setup something custom on the front-end). Backbone, ajaxes that all out and lets you create templates beforehand, so all you need to request from the backend is plain data objects, and you're essentially only needed to load one page.
您也可以在没有 Backbone 和 Express(或其他后端语言/框架)的情况下完成所有这些工作,但是您的所有页面都是对服务器的单独请求(除非您在前端设置了一些自定义内容)。Backbone,ajax 全部完成并允许您预先创建模板,因此您需要从后端请求的只是普通数据对象,并且您基本上只需要加载一个页面。
This is an oversimplification, but that's essentially it.
这过于简单化了,但本质上就是这样。
回答by Dave Ward
If you're accustomed to server-side MVC development, like ASP.NET MVC, Rails, Sinatra, Django, etc, using Express is going to be intuitive.
如果您习惯于服务器端 MVC 开发,如 ASP.NET MVC、Rails、Sinatra、Django 等,那么使用 Express 会很直观。
Backbone stops short of including a view engine, conventions for rendering partials, and that sort of thing. It also includes features like client-side browser history support that don't make much sense on the server-side. Though you could technically use it on the server-side with Node, Backbone is targeted at building single page interface apps on the client-side.
Backbone 没有包含视图引擎、渲染部分的约定等等。它还包括诸如客户端浏览器历史支持之类的功能,这些功能在服务器端没有多大意义。虽然从技术上讲,您可以在 Node 的服务器端使用它,但 Backbone 的目标是在客户端构建单页界面应用程序。
回答by evilcelery
Backbone is normally for use on the client side (browser) and Express is for the server side (NodeJS).
Backbone 通常用于客户端(浏览器),Express 用于服务器端(NodeJS)。
When Backbone is used on the server it's mostly for the models as Express doesn't provide any of these.
当在服务器上使用 Backbone 时,它主要用于模型,因为 Express 不提供任何这些。
回答by gaggina
Backbone is a front-end framework. Otherwise express is a back-end framework based on node.js.
Backbone 是一个前端框架。否则 express 是一个基于 node.js 的后端框架。
A common setup is express as rest api server and backbone as front-end framework.
一个常见的设置被表达为rest api server 和backbone 作为前端框架。
回答by Rubin bhandari
Backbone.js, Angular.js and Ember.js => Client Side JavaScript Frameworks, means they provide building blocks to build client side of web application. Node.js are of same kind and build on top of V8 Chrome engine.
Backbone.js、Angular.js 和 Ember.js => 客户端 JavaScript 框架,意味着它们提供构建块来构建 Web 应用程序的客户端。Node.js 是同类并且构建在 V8 Chrome 引擎之上。
Express is a framework built on top of Node.js to make our server side development easy
Express 是一个建立在 Node.js 之上的框架,使我们的服务器端开发变得容易