javascript - underscore中源码optimizeCb如何理解?
怪我咯
怪我咯 2017-04-10 16:02:13
0
1
625
  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) {
        return func.call(context, accumulator, value, index, collection);
      };
    }
    return function() {
      return func.apply(context, arguments);
    };
  };

上次同事说这段代码叫 偏函数 ,然后上网查了一些概念 http://www.vaikan.com/currying-partial-application/
之后又了解到 Higher-Order Functions,能否解释一下这些概念?以及上面的函数是不是偏函数?

怪我咯
怪我咯

走同样的路,发现不同的人生

répondre à tous(1)
阿神

这个之前讨论过。讨论的结果见这个链接:
关于underscore.js中optimizeCb函数中是否需要switch的问题

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!