Invokes interceptor with the object, and then returns object. The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain

对象的拦截器,用于在对象方法链中,调试对象

1 _.chain([1,2,3,200])
2   .filter(function(num) { return num % 2 == 0; })
3   .tap(alert)
4   .map(function(num) { return num * num })
5   .value();
6 => // [2, 200] (alerted)
7 => [4, 40000]

源码:

  _.tap = function(obj, interceptor) {
    interceptor(obj);
    return obj;
  };

  

 

 

posted on 2012-04-16 22:33  himanhimao  阅读(205)  评论(0编辑  收藏  举报