Backbone.js 和 Node.js 有什么区别?哪个最好?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15542187/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 13:57:51  来源:igfitidea点击:

What are the differences between Backbone.js and Node.js? And which is best?

node.jsbackbone.js

提问by Mohit Kumar

I'm feeling a bit confused, there are so many frameworks out there for Node.js related 'stuff'. Would someone be able to give me an overview of What are the differences between Backbone.js and Node.js? And which is best? Thanks in advance.

我感到有点困惑,有很多与 Node.js 相关的“东西”的框架。有人能给我一个关于 Backbone.js 和 Node.js 之间有什么区别的概述吗?哪个最好?提前致谢。

回答by Bharadwaj Srigiriraju

I am quoting it from a couple of sources here:

我从这里的几个来源引用它:

Firstly, to quote from the stack overflow question here:

首先,引用这里的堆栈溢出问题:

Most of the things you listed are related only because they are written in or otherwise use JavaScript. Comparing them is much like comparing apples to oranges. It's like asking what the difference is between a Toyota Camry and a V6 engine. They are related, but do different things.

Node

Also known as Node.js, Node is the JavaScript environment on which we run our server-side JavaScript code. It is based on the V8 JavaScript engine. All of the JavaScript code you write, or install and run from packages from NPM, GitHub, etc. is executed by the Node runtime environment.

Backbone

Backbonecan be likened to as a Model-View-Controllerframework for JavaScript. I believe it was originally written for the browser; it helps keep your client-side JavaScript clean by implementing most common MVC patterns (as well as a couple other things), allowing you to more easily connect your client-side JavaScript to your server-side code.

您列出的大多数内容只是因为它们是用 JavaScript 编写的或以其他方式使用 JavaScript 而相关的。比较它们就像比较苹果和橙子一样。这就像问丰田凯美瑞和 V6 发动机有什么区别。他们是相关的,但做不同的事情。

节点

Node 也称为 Node.js,是我们运行服务器端 JavaScript 代码的 JavaScript 环境。它基于V8 JavaScript 引擎。您编写的所有 JavaScript 代码,或者从 NPM、GitHub 等的包安装和运行的所有 JavaScript 代码都由 Node 运行时环境执行。

骨干

Backbone可以被比作 JavaScript的模型-视图-控制器框架。我相信它最初是为浏览器编写的;它通过实现最常见的 MVC 模式(以及其他一些东西)来帮助保持客户端 JavaScript 干净,让您可以更轻松地将客户端 JavaScript 连接到服务器端代码。

Also, this is from an answer for the same questionon Quora. Credit goes to Drew Harry:

此外,这是来自Quora 上同一问题的答案。归功于 Drew Harry:

They're almost completely unrelated. Traditionally, Backbone.js is a client library and Node.js is a way to write server-side applications in Javascript. Backbone aims to be a model + view system for binding data models with DOM elements that represent that model visually in a web page. Backbone also provides Collections of Models, as well as a bunch of utility functions for synchronizing those models with their server-side representations.

Node.js is just the v8 Javascript run-time environment packaged with a standard library to do useful server-side things with Javascript. There are lots of packages designed for Node (check out npm for ways to easily install those packages, Backbone included) that extend it to do all sorts of interesting things. It's possible to use Backbone.js with Node.js, but Backbone isn't particularly designed with use on the server in mind.

他们几乎完全不相关。传统上,Backbone.js 是一个客户端库,而 Node.js 是一种用 Javascript 编写服务器端应用程序的方法。Backbone 旨在成为一个模型 + 视图系统,用于将数据模型与 DOM 元素绑定,这些 DOM 元素在网页中可视化地表示该模型。Backbone 还提供了模型集合,以及一系列用于将这些模型与其服务器端表示同步的实用函数。

Node.js 只是与标准库一起打包的 v8 Javascript 运行时环境,用于使用 Javascript 执行有用的服务器端操作。有许多专为 Node 设计的包(查看 npm 以了解轻松安装这些包的方法,包括 Backbone),将其扩展为做各种有趣的事情。可以将 Backbone.js 与 Node.js 一起使用,但 Backbone 并不是专门为在服务器上使用而设计的。

Go and upvote the above answer(s) if you find the material helpful.

如果您发现这些材料有帮助,请对上述答案点赞。

回答by Michael Borgwardt

Pretty much the only things those two have in common is that they're Javascript based and have a lot of hype surrounding them (not undeserved though).

几乎这两者唯一的共同点是它们是基于 Javascript 的,并且围绕它们进行了大量炒作(尽管并非不该如此)。

node.js is a framework for Javascript server applications. It includes the V8 Javascript engine developed for Chrome. It's asynchronous and event-driven, so it's ideal for serving large numbers of small requests.

node.js 是 Javascript服务器应用程序的框架。它包括为 Chrome 开发的 V8 Javascript 引擎。它是异步和事件驱动的,因此非常适合处理大量小请求。

backbone.js is a framework for client-side web applications, specifically for so-called "single page web applications" where only a single HTML page is sent to the browser at the beginning, and every interaction thereafter is handled by AJAX requests and Javascript logic that transforms the page.

backbone.js 是一个用于客户端 Web 应用程序的框架,专门用于所谓的“单页 Web 应用程序”,即一开始只向浏览器发送一个 HTML 页面,之后的每次交互都由 AJAX 请求和 Javascript 处理转换页面的逻辑。

This means that the two can also work effectively together: an app implemented using backbone.js for the frontend could have its AJAX requests handled by a server part using node.js - a rather popular combination since it allows you to have an entire web app using only Javascript.

这意味着两者也可以有效地协同工作:前端使用backbone.js 实现的应用程序可以让服务器部分使用node.js 处理其AJAX 请求——这是一个相当流行的组合,因为它允许您拥有一个完整的Web 应用程序只使用 Javascript。

回答by slebetman

Backbone.js is a javascript library, similar to jQuery or YUI but addressing different needs.

Backbone.js 是一个 javascript 库,类似于 jQuery 或 YUI,但满足不同的需求。

Node.js is a javascript interpreter, similar to Internet Explorer or Firefox or Safari but addressing different needs.

Node.js 是一个 javascript 解释器,类似于 Internet Explorer 或 Firefox 或 Safari,但满足不同的需求。

I don't know much about backbone.js but I believe you can use it with Node.js since it uses regular javascript. You may need a DOM emulation layer for the DOM related stuff though.

我对backbone.js 了解不多,但我相信你可以将它与Node.js 一起使用,因为它使用常规javascript。不过,您可能需要一个 DOM 模拟层来处理 DOM 相关的内容。



Additional answer:

补充回答:

A bit of googling reveals that there are people out there using Backbone on Node.js. The advantage of this is obviously you'll be able to use the same framework and reuse code on both client and server.

谷歌搜索显示有人在 Node.js 上使用 Backbone。这样做的好处显然是您将能够在客户端和服务器上使用相同的框架并重用代码。

See: http://nerds.airbnb.com/weve-launched-our-first-nodejs-app-to-product

请参阅:http: //nerds.airbnb.com/weve-launched-our-first-nodejs-app-to-product



More additional answer:

更多附加答案:

With regards to semantics I see that some people disagree what some terms in computing means. While the terms are loosely used, and while they are somewhat interchangeable, they do have fairly well defined meanings.

关于语义,我看到有些人不同意计算中的某些术语的含义。虽然这些术语被松散地使用,虽然它们在某种程度上可以互换,但它们确实具有相当明确的含义。

In general, an interpreter is an executable, that is, a program that takes as input some data and executes it as a program. V8 is not this. It cannot take javascript by itself and run it. It needs to be compiled into another program, an interpreter in order to run javascript.

一般来说,解释器是一个可执行文件,即一个程序,它把一些数据作为输入并作为程序执行。V8不是这个。它不能单独使用 javascript 并运行它。它需要被编译成另一个程序,一个解释器才能运行 javascript。

V8 does ship with example code to build an interpreter though. That interpreter shipped with V8 is called V8-shell.

不过,V8 确实附带了示例代码来构建解释器。V8 附带的解释器称为 V8-shell。

An engine is a library that implements an interpreter. This is exactly what V8 is.

引擎是一个实现解释器的库。这正是V8。

The two terms above are somewhat interchangeable because the word "interpreter" can also validly be used in place of "engine" to describe what a library implements. But that usage of the word is similar to the usage of "MVC framework" or "UI toolkit" in that it is used as an adjective. So it is correct to say that an "interpreter" is a kind of library.

上述两个术语在某种程度上可以互换,因为“解释器”一词也可以有效地代替“引擎”来描述库实现的内容。但是这个词的用法类似于“MVC 框架”或“UI 工具包”的用法,因为它被用作形容词。所以说“解释器”是一种图书馆是正确的。

But the word was originally used to mean the binary that executes a programming language. When used this way one uses it as a noun as it refers to something on the file system. Used this way is similar to the usage of the "compiler". For example one would call clanga compiler in this sense and one would call llvm, the library used by clang, a compiler in the previous sense.

但是这个词最初用来表示执行编程语言的二进制文件。当以这种方式使用时,人们将它用作名词,因为它指的是文件系统上的某些东西。这种方式的使用类似于“编译器”的使用。例如,一个人会clang在这个意义上调用一个编译器,一个人会调用一个之前意义上的编译器,llvm由 使用的库clang

Lets take a look at something that is not javascript as an example:

让我们以一些不是 javascript 的东西为例:

  • tcl is a programming language

  • tcl is also the library that implements the interpreter for tcl. In other words the engine.

  • tclsh is the tcl interpreter

  • tcl 是一种编程语言

  • tcl 也是实现 tcl 解释器的库。换句话说,发动机。

  • tclsh 是 tcl 解释器

Let's take a look at another example:

让我们再看一个例子:

  • ruby is a programming language

  • RubyC is one of the many engines for ruby

  • ruby is the interpreter that uses RubyC

  • ruby 是一种编程语言

  • RubyC 是 ruby​​ 的众多引擎之一

  • ruby 是使用 RubyC 的解释器

Nobody uses the word "framework" when referring to the binary executable interpreter for the above two languages. It just sounds silly.

当提到上述两种语言的二进制可执行解释器时,没有人使用“框架”这个词。这听起来很傻。

But wait you say, Node.js refers to more than just node.exe. It truly provides a bunch of additional features that can be used as a good foundation to write great programs. In other words a framework.

但是等等你说,Node.js 不仅仅指的是 node.exe。它确实提供了一系列附加功能,可以用作编写出色程序的良好基础。换句话说,一个框架。

Well, yes. That being true does not make the usage of the word "interpreter" to refer to node.exe automatically invalid. Just as using the word "earth" to refer to the planet does not make using the word to refer to soil automatically invalid.

嗯,是。这是真的,并不会使使用“解释器”一词来指代 node.exe 自动无效。正如使用“地球”一词来指代行星并不会使使用该词来指代土壤自动失效。

Besides, those extra functionality? That's true for tcl and ruby as well. It's also true for C. Those extra functionality like fsand httpon Node.js are traditionally called standard library. While the Node.js project calls it a framework that's their choice. Almost nobody else calls their interpreter + standard library a framework. PHP for example is distributed exactly like Node.js with a bunch of very high level standard libraries but nobody would call PHP a framework. It's also a bit silly when people write actual frameworks on top of node - frameworks for a framework. But I'm not going to say they are wrong because they choose to call it that. It's just their way to describe what they've created. More power to them.

此外,那些额外的功能?对于 tcl 和 ruby​​ 也是如此。对于 C 也是如此。像Node.jsfshttpNode.js 上的那些额外功能传统上称为标准库。虽然 Node.js 项目称其为他们选择的框架。几乎没有其他人将他们的解释器 + 标准库称为框架。例如,PHP 的分布与 Node.js 完全一样,带有一堆非常高级的标准库,但没有人会将 PHP 称为框架。当人们在节点之上编写实际框架时,这也有点傻——框架的框架。但我不会说他们错了,因为他们选择这样称呼。这只是他们描述他们创造的东西的方式。给他们更多的权力。

What I am saying is that people who say that node.js is not an interpreter is ignoring the usage of the word throughout the history of computing. I don't know. Coming from an asian background it's natural to me to assume that everything belongs to multiple categories. Maybe it's a western idea that things belong strictly to specific categories that I don't quite get.

我想说的是,那些说 node.js 不是解释器的人忽略了整个计算历史中这个词的用法。我不知道。来自亚洲背景,我很自然地假设一切都属于多个类别。也许这是一种西方的想法,即事物严格属于我不太了解的特定类别。

So here are the facts:

以下是事实:

  1. Node.js is not simply a javascript library. You need node.exe to use the standard libraries that node ships with.

  2. Backbone.js is on the other hand a standard javascript library. It is not an executable.

  3. Node.js is the only example where an interpreter + library is called a framework so far. All other examples of framework I know of in programming refer to libraries that implement a design pattern.

  4. Calling something "B" does not automatically make calling it "A" invalid.

  1. Node.js 不仅仅是一个 javascript 库。您需要 node.exe 才能使用 node 附带的标准库。

  2. 另一方面,Backbone.js 是一个标准的 javascript 库。它不是可执行文件。

  3. Node.js 是迄今为止将解释器 + 库称为框架的唯一示例。我在编程中知道的所有其他框架示例都是指实现设计模式的库。

  4. 称某物为“B”并不会自动使称其为“A”无效。

One final thing: web browsers also come with a very large high level standard library for javascript. It's called the DOM (there's also a bunch of other stuff like Math and XMLHttpRequest but the DOM is the biggest). Accordingly one should call Internet Explorer and Firefox javascript frameworks but nobody does that.

最后一件事:Web 浏览器还附带了一个非常大的 javascript 高级标准库。它被称为 DOM(还有很多其他的东西,比如 Math 和 XMLHttpRequest,但 DOM 是最大的)。因此,人们应该调用 Internet Explorer 和 Firefox javascript 框架,但没有人这样做。

回答by Vivekanandan Murugesan

Both are javascript related but totally different.

两者都与javascript相关但完全不同。

Node is a interpreter/platform to execute javascript code in the server such as JDK or Ruby. To put it simple, you need NodeJS installed to interpret Backbone based script on the server.

Node 是一个解释器/平台,用于在 JDK 或 Ruby 等服务器中执行 javascript 代码。简单来说,你需要安装 NodeJS 来解释服务器上基于 Backbone 的脚本。

When it comes to server side MVC., Geddy, RailwayJS, Express etc., considered to be serving the purpose better than Backbone.

当涉及到服务器端 MVC.、Geddy、RailwayJS、Express 等,被认为比 Backbone 更好地服务于这个目的。

Whereas Backbone is a champion MVC framework in the client side.

而 Backbone 是客户端的冠军 MVC 框架。

回答by IdanHen

Node.js :

节点.js:

Javascript for backend side. ( like : php, ruby on rails, python, etc. )

后端的Javascript。(例如:php、ruby on rails、python 等)

Backbone.js :

骨干.js :

Javascript for frontend side ( running on the browser of your client ) backbone.js also uses jquery , more frameworks of javascript for client side are : 1. mootools 2. ExtJS 3. dojo 4. prototype and many more ...

前端的 Javascript(在客户端的浏览器上运行)backbone.js 也使用 jquery,客户端的更多 javascript 框架是: 1. mootools 2. ExtJS 3. dojo 4. 原型等等...

回答by koss

Node.js is a server-side platform designated for building network applications. It is built on Google's V8 Javascript Engine and uses asynchronous event-driven approach for building applications. Backbone.js is a simply javascript client library that makes it easier to create and maintain client-side code and comply with MVC pattern. Hence, they cannot be compared.

Node.js 是专门用于构建网络应用程序的服务器端平台。它建立在 Google 的 V8 Javascript 引擎之上,并使用异步事件驱动的方法来构建应用程序。Backbone.js 是一个简单的 javascript 客户端库,可以更轻松地创建和维护客户端代码并符合 MVC 模式。因此,它们无法进行比较。

Backbone.js has a lot of alternatives that use slightly different approach to achieve the same goal. Most known are: knockout, ember.jsand others. And it also can be plugged into node.js application.

Backbone.js 有很多替代方案,它们使用稍微不同的方法来实现相同的目标。最著名的是:knockoutember.js等。它也可以插入到 node.js 应用程序中。