zz775520666 发表于 2017-2-22 08:10:09

Underscore.js与nodejs相结合

今天发现这个Underscore.js,文档说
http://documentcloud.github.com/underscore/
引用
Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby)。

提供了许多类似ruby风格的函数,这是我所喜欢的。
看几个例子。
安装
引用
npm install underscore

在nodes.js中测试
_ = require 'underscore'
_.each , (num) -> console.log(num)#=>1 2 3
_.each
one : 1
tow:2
three:3
(num,key) ->
console.log "#{key}:#{num}"
a1 =_.map , (num)-> num * 3
_.each a1, (num) -> console.log(num)#=>3 6 9 12

有兴趣的读者可到上面的提到的网址看看。
页: [1]
查看完整版本: Underscore.js与nodejs相结合