Why lodash uses switch-case in negate function? [duplicate]
问题 This question already has answers here : Understanding the fast alternative apply() in lodash (2 answers) Closed 11 months ago . The following code is the source code of negate function in lodash. As we can see that when the length of parameters less than 4, it uses switch-case instead of using apply directly. What magic about this code? Does it make the performance better? And why the split point is 4? function negate(predicate) { if (typeof predicate != 'function') { throw new TypeError