1. 程式人生 > >uunderscore源碼閱讀筆記

uunderscore源碼閱讀筆記

value 沒有 cor count return con div on() collect

var optimizeCb = function(func, context, argCount) {   if (context === void 0) {     return func;   }   switch (argCount == null ? 3 : argCount) {     case 1:       return function(value) {       return func.call(context, value);     };     case 2:       return function(value, other) {       return func.call(context, value, other);     };     case 3:       return function(value, index, collection) {       return func.call(context, value, index, collection);     };     case 4:       return function(accumulator, value, index, collection) {       func.call(context, accumulator, value, index, collection);     };   }   return function() {     return func.apply(context, arguments);   }; };

call 比 apply要快

.apply 在運行前要對作為參數的數組進行一系列檢驗和深拷貝,.call 則沒有這些步驟

uunderscore源碼閱讀筆記