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.
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.
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.
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.
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'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With