Underscore.js,新的 JS Library

Simon Willison 的文章看到一個新的 JS library:「Underscore.js」,與 jQuery 有類似的想法:jQuery 是以 $ 為核心,Underscore.js 是以 _ 為核心。

除了對各種資料結構的操作外,還有一些與 event 有關的 function。如果可以自己處理各瀏覽器的 bug/workaround,用 Underscore.js 還不錯... (不過,自己手刻其實也還好...)

檔案大小的部份,Underscore.js 0.3.0 版的原始檔案 (含 comment) 是 15773 bytes,透過 yuicompress 處理過後是 5711 bytes,如果再加上 gzip 壓縮是 1937 bytes。

jQuery 1.3.2 的原始檔案 (含 comment) 是 120763 bytes,透過 yuicomopress 處理過後是 57254 bytes,gzip 後是 19711 bytes,差距大約都是十倍 (yuicompress 與 yuicompress + gzip 都是十倍左右,comment 的版本比較起來沒意義,因為實際上線時不會拿這個版本跑),但是功能多了很多,看使用的情況可以自己取捨。jQuery 另外一個好處是 Google 有提供 CDN,所以不需要自己 host...

Underscore.js 有提供一個頁面測試:「Underscore Test Suite」,而且這個頁面最下方的「Underscore Speed Suite」有直接產生測試圖的資料,數據直接以 Google Chart API 顯示,還附上 TinyURL 的短網址... XD

像我測試的結果就是:

One thought on “Underscore.js,新的 JS Library”

  1. ?? 怎麼跟 jQuery 比起來?兩者目的皆不同

    Underscore.js 的 bind/bindAll 並非 browser event binding,而是 function/data。Underscore.js 本身也沒有 selector engine。

    我想應該是跟jQuery配合一起用吧 (雖然小部份功能如 map, transform 等 overlap 了)。 又或者用 sizzle + underscore 也不錯?

Leave a Reply

Your email address will not be published. Required fields are marked *