我有以下代碼:下劃線使用多種功能於一體的在線
function doSomething(str){
return str+="a";
}
function anotherFunction(str){
return str+="b";
}
_.mixin({
doSomething:doSomething,
anotherFunction:anotherFunction
});
我想使用多個功能於一身行在一起,但我不能管理工作:
var output=_("startingtext").doSomething().anotherFunction();
我設法使用_.chain
工作,但我不確定是否應該使用鏈,因爲在他們的example他們使用的對象和東西,所以我真的懷疑這是字符串操作的方式。
對不起,我是新來強調:(任何幫助表示讚賞
你將不得不用_()重新包裝任何輸出,例如'return _(str +「a」);'在第一個函數中,在第二個函數中等價。 – Clemens 2012-01-31 19:54:42