The existing technique to wrap the subject of the method inside an array, which is mentioned here, was intended specifically for strings, turning "string" into ["string"]. The trick was using .split()
without arguments. After applying that trick, it was not so difficult to use the other little tricks to apply the method that was desired, and allow chaining on the result.
Of course, now that the subject is an array, we cannot use .split()
.
It turns out that you can use the following method to make it happen for arrays:
console.log(
[3, 4, 5].reduce([].constructor).slice(-1)
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…