JavaScript框架和库有什么区别? [重复]

时间:2021-11-22 03:27:54

Possible Duplicate:
Framework vs. Toolkit vs. Library

可能重复:框架与工具包与库

I would like to know what is the difference between a JavaScript framework and a library by using some example.

我想通过一些例子来了解JavaScript框架和库之间的区别。

For instance, jquery, backbone.js and jasmine are JavaScript framework or library? And why?

例如,jquery,backbone.js和jasmine是JavaScript框架还是库?为什么?

Can you provide some example of JavaScript framework and a library using the sentence Don't call Us, We'll call You.

你能提供一些JavaScript框架和一个库的例子吗?请不要打电话给我们,我们会打电话给你。

6 个解决方案

#1


50  

Even tho this question is highly subjective, my personal opinion about those two is this:

即使这个问题非常主观,我个人对这两个问题的看法是这样的:

  • Framework: this describes a given structure of "how" you should present your code. Pretty much like a code-template, along some helpers, constructors etc. to solve/simplify a specific problem or bring your architecture in "order". Examples, "Backbone", "requireJS", "socketIO".

    框架:这描述了您应该如何呈现代码的给定结构。非常像代码模板,一些帮助器,构造器等,以解决/简化特定问题或使您的架构“按顺序”。示例,“Backbone”,“requireJS”,“socketIO”。

  • Library: Is an entire toolkit which highly abstracts different layers, like browsers / DOM models / etc. Also as a good toolkit, it offers a lot of tools and neat stuff to work with, which in general, simplify your coding experience. Examples "jQuery", "MooTools", "YUI"

    库:是一个完整的工具包,可以高度抽象不同的层,如浏览器/ DOM模型/等。作为一个很好的工具包,它提供了许多工具和简洁的工作,通常可以简化您的编码体验。示例“jQuery”,“MooTools”,“YUI”

#2


29  

I agree with jAndy, in my opinion a framework imposes structure upon your code in order to address a particular problem and a library is a generic set of tools that aid you in various tasks, without necessarily addressing the same problem.

我同意jAndy,在我看来,一个框架强加了你的代码的结构,以解决一个特定的问题,一个库是一组通用的工具,可以帮助你完成各种任务,而不必解决同样的问题。

In this respect:

在这方面:

  • jQuery is a library because it abstracts a lot of browser incompatibilities but imposes no structure on your code.
  • jQuery是一个库,因为它抽象了许多浏览器不兼容性,但在代码上没有任何结构。
  • underscore.js is a library because it's a collection of utilities to manipulate data structures and other goodies.
  • underscore.js是一个库,因为它是一组操作数据结构和其他好东西的实用程序。
  • backbone.js is a framework because it structures your front-end code to match the MVC pattern.
  • backbone.js是一个框架,因为它构造您的前端代码以匹配MVC模式。
  • Jasmine is a framework because it structures your code so that you can do BDD easily.
  • Jasmine是一个框架,因为它构建了您的代码,因此您可以轻松地执行BDD。

Regarding your suggested example, frameworks fit the don't call us paradigm, because most of them impose the flow of the code (some sort of inversion of control). You call the libraries, they don't call your code.

关于你建议的例子,框架适合不要称之为范式的框架,因为它们中的大多数都强加了代码的流程(某种控制反转)。你调用库,他们不会调用你的代码。

This is a subjective opinion, so take it as such.

这是一个主观意见,所以就这样吧。

#3


2  

A framework encapsulates common application functionality, allowing the developer to focus on the parts that are unique to their application. That means the developer writes pieces of code that get called by the framework when various things happen; Ex: backbone.js, or jasmine. Libraries are packages of code that typically get called by your application to perform a task, like DOM manipulation or HTTP requests. Ex: jQuery.

框架封装了常见的应用程序功能,允许开发人员专注于应用程序独有的部分。这意味着开发人员会编写在各种事情发生时被框架调用的代码片段;例如:backbone.js,或茉莉。库是代码包,通常由应用程序调用以执行任务,如DOM操作或HTTP请求。例如:jQuery。

#4


0  

A JavaScript library is a library of pre-written JavaScript which allows for easier development of JavaScript-based applications.

JavaScript库是一个预编写的JavaScript库,可以更轻松地开发基于JavaScript的应用程序。

and Some JavaScript libraries, such as YUI, are classified as frameworks since they exhibit full-stack capabilities and properties not found in general JavaScript libraries.

一些JavaScript库(如YUI)被归类为框架,因为它们展示了通用JavaScript库中没有的全栈功能和属性。

#5


0  

JavaScript is a scripting language.

JavaScript是一种脚本语言。

JQuery is a JavaScript library that handles many commonly used features and also handles the differences between, e.g., Internet Explorer and standards-compliant browsers. It's something you can use to reduce the amount of work when creating web-based applications.

JQuery是一个JavaScript库,可以处理许多常用功能,还可以处理Internet Explorer和符合标准的浏览器之间的差异。在创建基于Web的应用程序时,您可以使用它来减少工作量。

#6


0  

There is no real definition of the difference between those two, but in general I would say that a framework is a more general "multi-tool" thing than a library, which is usually very specialized.

这两者之间没有真正的区别,但总的来说,我会说框架是比图书馆更通用的“多工具”,通常非常专业。

For example, Sylvester is a matrix and vector math library. It is very specific in its functionality.

例如,西尔维斯特是一个矩阵和矢量数学库。它的功能非常具体。

A framework like Prototype on the other hand offers much more than just a limited set of very specialized functionality. It may even use or consist of multiple libraries internally.

另一方面,像Prototype这样的框架提供的不仅仅是一组有限的非常专业的功能。它甚至可以在内部使用或由多个库组成。

Important: In the end, people use "framework" and "library" as they see fit. Unfortunately ;)

重要提示:最后,人们会根据自己的需要使用“框架”和“库”。不幸的是;)

#1


50  

Even tho this question is highly subjective, my personal opinion about those two is this:

即使这个问题非常主观,我个人对这两个问题的看法是这样的:

  • Framework: this describes a given structure of "how" you should present your code. Pretty much like a code-template, along some helpers, constructors etc. to solve/simplify a specific problem or bring your architecture in "order". Examples, "Backbone", "requireJS", "socketIO".

    框架:这描述了您应该如何呈现代码的给定结构。非常像代码模板,一些帮助器,构造器等,以解决/简化特定问题或使您的架构“按顺序”。示例,“Backbone”,“requireJS”,“socketIO”。

  • Library: Is an entire toolkit which highly abstracts different layers, like browsers / DOM models / etc. Also as a good toolkit, it offers a lot of tools and neat stuff to work with, which in general, simplify your coding experience. Examples "jQuery", "MooTools", "YUI"

    库:是一个完整的工具包,可以高度抽象不同的层,如浏览器/ DOM模型/等。作为一个很好的工具包,它提供了许多工具和简洁的工作,通常可以简化您的编码体验。示例“jQuery”,“MooTools”,“YUI”

#2


29  

I agree with jAndy, in my opinion a framework imposes structure upon your code in order to address a particular problem and a library is a generic set of tools that aid you in various tasks, without necessarily addressing the same problem.

我同意jAndy,在我看来,一个框架强加了你的代码的结构,以解决一个特定的问题,一个库是一组通用的工具,可以帮助你完成各种任务,而不必解决同样的问题。

In this respect:

在这方面:

  • jQuery is a library because it abstracts a lot of browser incompatibilities but imposes no structure on your code.
  • jQuery是一个库,因为它抽象了许多浏览器不兼容性,但在代码上没有任何结构。
  • underscore.js is a library because it's a collection of utilities to manipulate data structures and other goodies.
  • underscore.js是一个库,因为它是一组操作数据结构和其他好东西的实用程序。
  • backbone.js is a framework because it structures your front-end code to match the MVC pattern.
  • backbone.js是一个框架,因为它构造您的前端代码以匹配MVC模式。
  • Jasmine is a framework because it structures your code so that you can do BDD easily.
  • Jasmine是一个框架,因为它构建了您的代码,因此您可以轻松地执行BDD。

Regarding your suggested example, frameworks fit the don't call us paradigm, because most of them impose the flow of the code (some sort of inversion of control). You call the libraries, they don't call your code.

关于你建议的例子,框架适合不要称之为范式的框架,因为它们中的大多数都强加了代码的流程(某种控制反转)。你调用库,他们不会调用你的代码。

This is a subjective opinion, so take it as such.

这是一个主观意见,所以就这样吧。

#3


2  

A framework encapsulates common application functionality, allowing the developer to focus on the parts that are unique to their application. That means the developer writes pieces of code that get called by the framework when various things happen; Ex: backbone.js, or jasmine. Libraries are packages of code that typically get called by your application to perform a task, like DOM manipulation or HTTP requests. Ex: jQuery.

框架封装了常见的应用程序功能,允许开发人员专注于应用程序独有的部分。这意味着开发人员会编写在各种事情发生时被框架调用的代码片段;例如:backbone.js,或茉莉。库是代码包,通常由应用程序调用以执行任务,如DOM操作或HTTP请求。例如:jQuery。

#4


0  

A JavaScript library is a library of pre-written JavaScript which allows for easier development of JavaScript-based applications.

JavaScript库是一个预编写的JavaScript库,可以更轻松地开发基于JavaScript的应用程序。

and Some JavaScript libraries, such as YUI, are classified as frameworks since they exhibit full-stack capabilities and properties not found in general JavaScript libraries.

一些JavaScript库(如YUI)被归类为框架,因为它们展示了通用JavaScript库中没有的全栈功能和属性。

#5


0  

JavaScript is a scripting language.

JavaScript是一种脚本语言。

JQuery is a JavaScript library that handles many commonly used features and also handles the differences between, e.g., Internet Explorer and standards-compliant browsers. It's something you can use to reduce the amount of work when creating web-based applications.

JQuery是一个JavaScript库,可以处理许多常用功能,还可以处理Internet Explorer和符合标准的浏览器之间的差异。在创建基于Web的应用程序时,您可以使用它来减少工作量。

#6


0  

There is no real definition of the difference between those two, but in general I would say that a framework is a more general "multi-tool" thing than a library, which is usually very specialized.

这两者之间没有真正的区别,但总的来说,我会说框架是比图书馆更通用的“多工具”,通常非常专业。

For example, Sylvester is a matrix and vector math library. It is very specific in its functionality.

例如,西尔维斯特是一个矩阵和矢量数学库。它的功能非常具体。

A framework like Prototype on the other hand offers much more than just a limited set of very specialized functionality. It may even use or consist of multiple libraries internally.

另一方面,像Prototype这样的框架提供的不仅仅是一组有限的非常专业的功能。它甚至可以在内部使用或由多个库组成。

Important: In the end, people use "framework" and "library" as they see fit. Unfortunately ;)

重要提示:最后,人们会根据自己的需要使用“框架”和“库”。不幸的是;)