jquery 是 javascript 库还是框架?

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

Is jquery a javascript library or framework?

javascriptjqueryframeworks

提问by rahul dagli

Here, jquery is mentioned under framework category: http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks

在这里,框架类别下提到了 jquery:http: //en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks

Is jquery a javascript library or framework?

jquery 是 javascript 库还是框架?

回答by GregL

A library. According to the homepage, and which I agree with.

图书馆。根据主页,我同意。

A framework is something that usually forces a certain way of implementing a solution, whereas jQuery is just a tool to make implementing what you want to do easier.

框架通常是强制以某种方式实现解决方案的东西,而 jQuery 只是一种工具,可以使实现您想做的事情变得更容易。

回答by Saeed

For sure, it's a javascript library. But about being a framework or not,I just think it's not a framework. Have a look on wikipedia definition of software-framework:

当然,它是一个 javascript 库。但是关于是否是一个框架,我只是认为它不是一个框架。看看维基百科对软件框架的定义

It is a collection of software libraries providing a defined application programming interface.

它是提供定义的应用程序编程接口的软件库的集合。

And jQuery is just a single library. After that it says:

jQuery 只是一个库。之后它说:

Frameworks contain key distinguishing features that separate them from normal libraries:

  1. inversion of control - In a framework, unlike in libraries or normal user applications, the overall program's flow of control is not dictated by the caller, but by the framework.

框架包含将它们与普通库区分开来的关键特征:

  1. 控制反转 - 在框架中,与库或普通用户应用程序不同,整个程序的控制流不是由调用者决定的,而是由框架决定的。

So, I think it's not a framework.

所以,我认为这不是一个框架。

回答by Harke

According to the angularjs web site

根据angularjs网站

  • a library - a collection of functions which are useful when writing web apps. Your code is in charge and it calls into the library when
    it sees fit. E.g., jQuery.
  • frameworks - a particular implementation of a web application, where your code fills in the details. The framework is in charge and it calls into your code when it needs something app specific. E.g., durandal, ember, etc.
  • 库 - 编写 Web 应用程序时有用的函数集合。您的代码负责并在
    它认为合适时调用库。例如,jQuery。
  • 框架 - Web 应用程序的特定实现,您的代码会在其中填写详细信息。该框架负责并在需要特定于应用程序的内容时调用您的代码。例如,杜兰达尔、余烬等。

回答by Fiodar Sazanavets

Framework and libarry are not necessarily mutually exclusive terms. Framework is typically a libarry or a collection of libraries.

框架和库不一定是相互排斥的术语。框架通常是一个库或库的集合。

Strictly speaking, jQuery is a library, but, to an extent, it does meet the definition of a software framework. Although many would argue that jQuery doesn't meet the definition of a software framework strictly enough, the fact is that no other JavaScript framework fully meets the definition of a framework either.

严格来说,jQuery 是一个库,但在某种程度上,它确实符合软件框架的定义。尽管许多人会争辩说 jQuery 不够严格地满足软件框架的定义,但事实是,没有其他 JavaScript 框架完全满足框架的定义。

One of the defining characteristics of a software framework is that its code is protected from modifications. In JavaScript, this clearly isn't the case. Any libraries or frameworks that can be called into your client-side code are modifiable, although it would be against best practices to alter them. Therefore, if it is permissible to call Bootstrap or AngularJS a framework, there is no reason why jQuery cannot be called a framework either. This linkcontains a more detailed explanation of how jQuery meets the criteria to be called a framework.

软件框架的定义特征之一是其代码不受修改。在 JavaScript 中,情况显然不是这样。任何可以调用到客户端代码中的库或框架都是可修改的,尽管更改它们将违反最佳实践。因此,如果可以将 Bootstrap 或 AngularJS 称为框架,那么 jQuery 也没有理由不能称为框架。此链接包含有关 jQuery 如何满足被称为框架的标准的更详细说明。

Perhaps the best explanation of why jQuery is more of a framework than a library is the fact that as a developer, you can chose not to use any of its framework-like functionalities. You can, for example, mix a simple jQuery statement with a standard JavaScript statement on the same line. AngularJS and Bootstrap typically don't allow you to do this. Therefore, the accurate answer whether jQuery is a framework or not is "it depends whether you chose to use it as a framework or not".

或许 jQuery 更像是一个框架而不是一个库的最好解释是,作为开发人员,您可以选择不使用其任何类似框架的功能。例如,您可以在同一行中混合使用简单的 jQuery 语句和标准的 JavaScript 语句。AngularJS 和 Bootstrap 通常不允许你这样做。因此,jQuery 是否是框架的准确答案是“这取决于您是否选择将其用作框架”。

回答by Durandal

I agree with all the answers here that jQuery itself is indeed a library, not a framework. As specified by Saeed's answer, one of the key distinguishing features is inversion of control. You could however use jQuery's functionality to create a framework of your own.

我同意这里的所有答案,即 jQuery 本身确实是一个库,而不是一个框架。正如 Saeed 的回答所指出的,关键的区别特征之一是控制反转。但是,您可以使用 jQuery 的功能来创建您自己的框架。

Examples: there are projects built on top of jQuery that are defined as frameworks: jQuery Mobile: A Touch-Optimized Web Framework, JavaScriptMVCand sammy.jsto name a few.

示例:有一些基于 jQuery 构建的项目被定义为框架:jQuery Mobile:A Touch-Optimized Web FrameworkJavaScriptMVCsammy.js等等。

There are also other libraries built on top of jQuery, like jQuery UI

还有其他基于 jQuery 构建的库,例如jQuery UI

Some of it seems like semantics when defining what a library is vs a framework, but those examples help draw the line for me.

在定义库与框架的区别时,有些似乎是语义,但这些示例有助于为我划清界限。

回答by pinkman

If we talk about Inversion of control, which almost everyone in the above thread talks about then jQuery is a FRAMEWORK.

如果我们谈论控制反转,几乎上面线程中的每个人都在谈论,那么 jQuery 就是一个框架。

It has got IOC e.g when we write the function $(document).ready{}...it is the container which calls this method and we simply put our code inside the braces. We are not the Caller of this method and hence "Inversion of Control"

例如,当我们编写函数$(document).ready{}时,它有 IOC ……它是调用此方法的容器,我们只需将代码放在大括号内。我们不是这个方法的调用者,因此是“控制反转”

This way jQuery is a FRAMEWORK.

这样 jQuery 就是一个框架。