Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于underscore.js中optimizeCb函数中是否需要switch的问题 #4

Open
ellyliang opened this issue Sep 24, 2015 · 0 comments
Open

Comments

@ellyliang
Copy link

代码

var optimizeCb = function(func, context, argCount) {
    if(context === void 0) {
      return func;
    }

    switch(argCount = argCount || 3) {
      case 1 :
        return function(value) {
          return func.call(context, value);
        };
      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);
    };

  };

解答如下:

image

相关文章

image

image

image

关于性能优化的问题

image

小鱼分享的有关优化js性能的文章

感谢i蒹葭从风提供hax的讲解,也感谢hax的讲解

@jianjiade jianjiade changed the title 关于optimizeCb函数中是否需要switch的问题 关于underscore.js中optimizeCb函数中是否需要switch的问题 Sep 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants