I have the following code:
function doSomething(str){
return str+="a";
}
function anotherFunction(str){
return str+="b";
}
_.mixin({
doSomething:doSomething,
anotherFunction:anotherFunction
});
I want to use multiple functions together in one line, but I can’t manage to work:
var output=_("startingtext").doSomething().anotherFunction();
I managed to make it work using _.chain, but I am not sure if chain should be used because in their example they are using with objects and stuff, so I really doubt this is the way to go for string manipulation.
Sorry, I am new to underscore :(, any help is appreciated.
_.chain()is exactly the way to go.In Javascript, everything is an object. Including a string. You were doing it right the first time.
_.chain()wraps your string in an object that can be passed forward, chain-style, and unpacked at the end with a call to value().