underscore源码

https://img4.mukewang.com/5bdfeb32000114b005260374.jpg

求教:上面是underscore的一段源码,让我比较困惑的是switch的作用,我觉得完全不需要switch啊,直接如果判断context==null,如果不是直接返回

return function () {            return func.apply(context, arguments)
        }

上面这个不就可以吗?求各位大神指教啊?它的注释中说是

// Internal function that returns an efficient (for current engines) version    
// of the passed-in callback, to be repeatedly applied in other Underscore    // functions.

请问是对于比较少参数的时候,用call这种方法会快不少吗?感觉有别的深意啊,毕竟我不觉得这个速度会差很多,可是实在想不到区别了


慕田峪7331174
浏览 582回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript