Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any good underscore.js alternatives that extend the core js classes?

I find the _.something(somevar, some_function_or_other_thing); "syntax" quite ugly. What are some good alternatives that use ruby-like iterators and similar stuff:

10..times(function(i) {
   console.log(i);
});

uppercasefoobar = ["foo", "bar"].each(function(i) {
    return i.toUpperCase();
});

Also, I am using node.js, so it should focus more on the code than DOM stuff.

like image 370
phillips1012 Avatar asked Nov 06 '13 04:11

phillips1012


People also ask

Do you need underscore js?

Underscore ( _ ) is just a plain valid character for variable/function name, it does not bring any additional feature. However, it is a good convention to use underscore to mark variable/function as private. You can check Underscore prefix for property and method names in JavaScript for some previous discussion.

Is Lodash compatible with underscore?

Because Lodash is updated more frequently than Underscore. js, a lodash underscore build is provided to ensure compatibility with the latest stable version of Underscore.

Is underscore allowed in JavaScript?

Normally underscore is used in JavaScript to define any field private or public without using private and public keywords. By using underscore (_) we can easily identify the private class and member of that class, so it is a widely used concept in programming language and all programmers will identify it.


1 Answers

Suprised no one mentioned Lo-Dash. Lo-Dash is a superset of Underscore, adding numerous methods. John-David Dalton (creator of Lo-Dash) explains the key differences between the two libraries in answering an SO question here.

edit: found a detailed blog post "Say hello to Lo-Dash", detailing the background to the library and comparisons to other so called 'js utility belts'.

like image 177
Tony Cronin Avatar answered Sep 17 '22 22:09

Tony Cronin