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.
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)
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:
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.
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.
发布评论
评论(4)
摘自 underscore 网站:
Underscore 更适合数据操作,并将许多 Ruby 方法引入 JavaScript。有一些交叉,但不足以使它们相互排斥。
Taken from the underscore site:
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.
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
如果您担心重叠,并且不需要 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.