underscore的使用

1、链接

  npm underscore:https://www.npmjs.com/package/underscore

  官网:https://underscorejs.org/

2、npm安装:npm install underscore

3、简单使用

var _ = require("underscore");

var array = _.map([1, 2, 3], (x) => x * x);
console.log(array); // [ 1, 4, 9 ]

var array2 = _.map(["A", "B", "C"], (x) => x.toLowerCase());
console.log(array2); //[ 'a', 'b', 'c' ]

// template():声明模板数据
var fn = _.template("<h2>hello, I am <%= name %>!</h2>"); // template()函数的返回值类型为函数
var html = fn({name: 'hanmeimei'});
console.log(html); // <h2>hello, I am hanmeimei!</h2>
原文地址:https://www.cnblogs.com/xy-ouyang/p/11129443.html