I am working with both underscore and underscore.string, and there is a conflict with the function .reverse() since both have a function with the same name.
To avoid conflict, we need to use _.str like this:
_.str.reverse("foobar"); //.reverse("foobar") won't work
However, don’t know how to use the underscore.string’s .reverse() inside a chain.
I have tried with the following:
var something=_.chain("hello world!")
.capitalize()
//_.str
//_.str()
//.str
//.str()
.reverse()
.value();
But don’t work… Any ideas?
You could use
_.mixinto add the_.str.reversefunction to the underscore object with another name so it doesn’t clash with arrays’ reverse:And a JSFiddle demo, of course.
Note that after doing that
strReversewill also be otherwise accessible in the underscore object: