- 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——常量方法
语法
_.constant(value)
constant方法创建了一个函数,该函数返回传递为参数的相同值。请参阅以下示例
示例
var _ = require('underscore');
var value = {name: 'Sam'};
//Example 1: Check if constant returns same object
console.log(value === _.constant(value)());
value = 1;
//Example 2: Check if constant returns same object
console.log(value === _.constant(value)());
将上述程序保存到tester.js中。运行以下命令来执行该程序。
命令
\>node tester.js
输出
true true
underscorejs_utilities.htm
广告