- Underscore.JS 教程
- Underscore.JS —— 主页
- Underscore.JS —— 概览
- Underscore.JS —— 环境设置
- Underscore.JS —— 迭代集合
- Underscore.JS —— 处理集合
- Underscore.JS —— 迭代数组
- Underscore.JS —— 处理数组
- Underscore.JS —— 方法
- Underscore.JS —— 映射对象
- Underscore.JS —— 更新对象
- Underscore.JS —— 比较对象
- Underscore.JS —— 工具
- Underscore.JS —— 链式操作
- Underscore.JS 有用资源
- Underscore.JS —— 快速指南
- Underscore.JS —— 有用资源
- Underscore.JS —— 讨论
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
广告