Underscore.JS —— tap 方法



语法

_.tap(object, interceptor)

tap 方法对对象应用拦截,然后返回对象。请参见以下示例 −

示例

var _ = require('underscore');

_.chain([1, 2, 3, 4, 5, 6])
  .filter(function(num) { return num % 2 == 0; })
  .tap(console.log)
  .map(function(num) { return num * num })
  .value();

将以上程序另存为 **tester.js**。运行以下命令以执行该程序。

命令

\>node tester.js

输出

{ 2, 4, 6 }
underscorejs_updating_objects.htm
广告
© . All rights reserved.