Lodash 遵循 MIT 开源协议发布,并且支持最新的运行环境。 查看各个构件版本的区别并选择一个适合你的版
安装
浏览器环境:
1
<scriptsrc="lodash.js"></script>
通过 npm:
1 2
$ npm i -g npm $ npm i --save lodash
Node.js:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Load the full build. var _ = require('lodash'); // Load the core build. var _ = require('lodash/core'); // Load the FP build for immutable auto-curried iteratee-first data-last methods. var fp = require('lodash/fp');
var deep = _.cloneDeep(objects); console.log(deep[0] === objects[0]); // => false
日期
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//y-m-d getDate() { const date = newDate(); let year = date.getFullYear(); let month = date.getMonth() + 1; let day = date.getDate(); month = month.toString().padStart(2, '0') day = day.toString().padStart(2, '0') return`${year}-${month}-${day}`; } //h-m-s getTime() { const date = newDate(); let hour = date.getHours().toString().padStart(2, '0'); let minute = date.getMinutes().toString().padStart(2, '0'); let second = date.getSeconds().toString().padStart(2, '0'); return`${hour}:${minute}:${second}`; }