Cer*_*ius 2 javascript methods fluent chaining
我尝试链接一些数组和字符串方法,但它不起作用.如果有人能向我解释为什么这样的函数不起作用,那就太好了:
const scream = text => text.split('').push('!').join('').toUpperCase()
Run Code Online (Sandbox Code Playgroud)
您可以使用Array#concat返回一个具有另一个值的数组,而不是Array#push返回新的长度,但不是后续连接(需要数组)的流畅接口的一部分.
const scream = text => text.split('').concat('!').join('').toUpperCase();
console.log(scream('hi'));Run Code Online (Sandbox Code Playgroud)