ITeye博客

Underscore.js与nodejs相结合

biyeah · 2011-12-14 11:18 · nodejs · Web前端 · Markdown

今天发现这个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 [1, 2, 3], (num) -> console.log(num)#=>1 2 3

_.each
  one : 1
  tow:2
  three:3
  (num,key) ->
    console.log "#{key}:#{num}"

a1 =  _.map [1,2,3,4], (num)-> num * 3
_.each a1, (num) -> console.log(num)#=>3 6 9 12

有兴趣的读者可到上面的提到的网址看看。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。