Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Underscore.js and jQuery complement each other? [closed]

I'm just starting to learn JavaScript, and stumbled over Underscore.js and jQuery. Underscore looks really cool but I wonder if jQuery does not already provide functions similar to Underscore. So, is it worthwhile to use both?

like image 830
helpermethod Avatar asked Jan 18 '12 08:01

helpermethod


People also ask

Is underscore JS still used?

Lodash and Underscore are great modern JavaScript utility libraries, and they are widely used by Front-end developers.

Should you use underscore JS?

the Underscore Prefix in JavaScript VariablesThe underscore _ is simply an acceptable character for variable/function names; it has no additional functionality. Underscore variable is the standard for private variables and methods. There is no true class privacy in JavaScript.

Why is JavaScript underscore better?

Instead of having to cater to the expectations of the JavaScript language, Underscore helps you write code that clearly expresses your intentions. The next developer - or the future you - will have an easier time understanding how you wanted your code to work.


4 Answers

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.

like image 53
Gazler Avatar answered Sep 22 '22 10:09

Gazler


  • 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)
like image 25
rkw Avatar answered Sep 18 '22 10:09

rkw


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

like image 35
Umesh Patil Avatar answered Sep 18 '22 10:09

Umesh Patil


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.

like image 36
DigitalDesignDj Avatar answered Sep 22 '22 10:09

DigitalDesignDj