{"id":2187,"date":"2011-12-20T10:27:48","date_gmt":"2011-12-20T16:27:48","guid":{"rendered":"http:\/\/bililite.nfshost.com\/blog\/?p=2187"},"modified":"2011-12-20T10:27:48","modified_gmt":"2011-12-20T16:27:48","slug":"nice-javascript-library-underscore-js","status":"publish","type":"post","link":"https:\/\/bililite.com\/blog\/2011\/12\/20\/nice-javascript-library-underscore-js\/","title":{"rendered":"Nice Javascript library: underscore.js"},"content":{"rendered":"<p>Modern javascript provides a host of cool functional-programming toys like <code>forEach<\/code> and <code>reduce<\/code>, but I'm stuck with IE* at work, which does not. jQuery fills some of those gaps (it has <code class=\"language-javascript\">$.each<\/code> and <code class=\"language-javascript\">$.map<\/code>) but not everything one would want.<\/p>\n<p>Enter <a href=\"http:\/\/documentcloud.github.com\/underscore\/\">underscore.js<\/a>, which bills itself as \"the tie to go along with jQuery's tux.\"<\/p>\n<p>It doesn't modify any native objects, requiring you to wrap them as <code class=\"language-javascript\">_([1,2,3]).map(function(x) {return 2*x;})<\/code>, which returns <code class=\"language-javascript\">[2,4,6]<\/code>. Chaining has to be explicitly enabled, <code class=\"language-javascript\">_([1,2,3]).chain().map(function(x) {return 2*x;}).reduce(function(memo, num){ return memo + num; }, 0)<\/code> returns <code class=\"language-javascript\">12<\/code>.<\/p>\n<p>Looks useful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Modern javascript provides a host of cool functional-programming toys like forEach and reduce, but I'm stuck with IE* at work, which does not. jQuery fills some of those gaps (it has $.each and $.map) but not everything one would want. Enter underscore.js, which bills itself as \"the tie to go along with jQuery's tux.\" It [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/2187"}],"collection":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/comments?post=2187"}],"version-history":[{"count":4,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/2187\/revisions"}],"predecessor-version":[{"id":2191,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/2187\/revisions\/2191"}],"wp:attachment":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/media?parent=2187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/categories?post=2187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/tags?post=2187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}