Underscore.js 和 jQuery 互补吗?

发布于 2024-12-27 23:16:35 字数 1431 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

旧伤慢歌 2025-01-03 23:16:35

摘自 underscore 网站:

它是与 jQuery 的燕尾服和 Backbone.js 的吊带搭配的领带。

Underscore 更适合数据操作,并将许多 Ruby 方法引入 JavaScript。有一些交叉,但不足以使它们相互排斥。

Taken from the underscore site:

It's the tie to go along with jQuery's tux, and Backbone.js's suspenders.

Underscore is more suited to data manipulation and brings many Ruby methods to JavaScript. There is some crossover, but not enough to make them mutually exclusive.

傲鸠 2025-01-03 23:16:35
  • jQuery 将处理您的大部分 dom 操作,
  • backbone.js 将帮助您组织所有代码,并为您的 js 应用程序提供一些结构(mvc 模式)
  • underscore.js 将为您提供真正有用的低级实用程序。在我真正进入 js 应用程序之前,我永远不会需要这个库(这也是backbone.js 的要求)
  • jQuery will take care of most of your dom manipulation
  • backbone.js will help you organize all of your code and give your js application some structure (mvc pattern)
  • underscore.js will give you really useful low-level utility. I would have never needed this library until I really got into js apps (it's also a requirement for backbone.js)
疏忽 2025-01-03 23:16:35

Underscore总共提供了60个用于处理数据/代码的函数。人们一致认为,许多功能都存在于其他库中,例如 jQuery、Prototype 或 script.aculo.us。例如,jQuery 中存在each、map、find、filter 或toArray 等函数。这些也用下划线表示。这是为了使库独立于 jQuery。

何时使用 Underscore?

目前,它广泛与 Backbone.js 一起使用,以使用 MVC 架构创建单页 Javascript Web 应用程序。 underscore.js 最重要的能力是模板化的能力(这是 jQuery 做不到的)。该库还有许多其他有用的功能,这些功能独立于其他 Javascript 库。

下面是 Underscore 提供的功能列表:

集合:
each、map、reduce、reduceRight、find、filter、reject、all、any、include、invoke、pluck、max、min、sortBy、groupBy、sortedIndex、shuffle、toArray、size

数组:
first,initial,last,rest,compact,flatten,without,union,intersection,difference,uniq,zip,indexOf,lastIndexOf,range

功能:
绑定、bindAll、记忆、延迟、延迟、节流、反跳、一次、之后、包装、组合

对象:
键、值、函数、扩展、默认值、克隆、tap、isEqual、isEmpty、isElement、isArray、isArguments、isFunction、isString、isNumber、isBoolean、isDate、isRegExp、isNaN、isNull、isUndefined

实用程序:
noConflict、身份、时间、mixin、uniqueId、转义、模板

Underscore provides a total of 60 functions for processing data/code. It is agreed that many of the functionalities are present in other libraries like jQuery, Prototype or script.aculo.us. For example, functions like each, map, find, filter or toArray are present in jQuery. These are in Underscore also. This is to make the library independent of jQuery.

When to use Underscore?:

Currently, it is widely used with Backbone.js to use MVC architecture for creating a one page Javascript Web app. The most significant ability of underscore.js is the ability of templating (which jQuery can not do). This library has many other useful functions, which are independent of other Javascript libraries.

Find below a list of functions provided by Underscore:

Collections:
each,map,reduce,reduceRight,find,filter,reject,all,any,include,invoke,pluck,max,min,sortBy,groupBy,sortedIndex,shuffle,toArray,size

Array:
first,initial,last,rest,compact,flatten,without,union,intersection,difference,uniq,zip,indexOf,lastIndexOf,range

Function:
bind,bindAll,memoize,delay,defer,throttle,debounce,once,after,wrap,compose

Object:
keys,values,functions,extend,defaults,clone,tap,isEqual,isEmpty,isElement,isArray,isArguments,isFunction,isString,isNumber,isBoolean,isDate,isRegExp,isNaN,isNull,isUndefined

Utitity:
noConflict,identity,times,mixin,uniqueId,escape,template

叶落知秋 2025-01-03 23:16:35

如果您担心重叠,并且不需要 JQuery AJAX 之类的东西,那么您可能会考虑仅使用名为 Sizzle 的 JQuery 选择器引擎。

http://sizzlejs.com/

请注意,这并不适用于所有项目,通过使用 Sizzle 和 Underscore,您将失去一些 JQuery 功能(例如 AJAX ),您需要考虑您的特定应用程序真正需要什么。

If you are concerned about overlap, and do not need things like JQuery AJAX, then you might consider using just the JQuery selector engine, named Sizzle.

http://sizzlejs.com/

Note that this is not for all projects, by using Sizzle and Underscore you will lose some JQuery functionality (like AJAX), you need to consider what you really need for your specific application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文