- Backbone.js Patterns and Best Practices
- Swarnendu De
- 349字
- 2021-07-19 18:28:20
Using Underscore.js
Underscore.js (http://underscorejs.org/) is a powerful utility library that provides a lot of functional programming support for your JavaScript code. In general, JavaScript comes up with a very low number of utility methods on its own, and most of the time we need to either develop our own functions or depend on another library for these methods. Underscore comes up with a bagful of highly efficient utility methods, which makes it an excellent tool for your JavaScript projects. The functions it provides can be grouped into the following sections:
- Collections (Array or Object)
- Arrays
- Functions
- Objects
- Utility
- Chaining
These include functions for iterations, sorting, filtering, conversions, templating, comparisons, scope binding, and many more. The main benefits of using this small library are as follows:
- It helps you to make the JavaScript code more intuitive and concise.
- In addition to the convenient methods, Underscore also implements cross-browser versions of newer JavaScript functions, which are only available in modern browsers. Underscore will detect whether the browser supports the method, and will use the native implementation if it is present. This boosts the function's performance to a great extent.
- The minified and gzipped version of the library weighs only 4.9 KB, which leaves little excuse for not taking advantages of this library.
- The library is completely DOM-free—so you can use it for your server-side JavaScript code as well.
- Excellent documentation similar to Backbone.js with examples is available at http://underscorejs.org/.
Backbone.js has a hard dependency on Underscore.js, and you are bound to use it if you are developing your applications with Backbone.js. However, even when you are not using Backbone, we encourage you to use Underscore.js for your JavaScript projects. It adds no overhead, integrates easily, and makes your code more robust even when you are not aware of all the underlying engineering principles employed by this library.
There is another library named Lo-dash
(http://lodash.com), which provides an Underscore built to perform drop-in replacement of the Underscore.js library. It is said to have a slightly better performance than Underscore.js. You can try either of them to achieve the same result.
- Mastering ServiceStack
- Debian 7:System Administration Best Practices
- 劍指JVM:虛擬機(jī)實(shí)踐與性能調(diào)優(yōu)
- SQL Server 2012數(shù)據(jù)庫技術(shù)及應(yīng)用(微課版·第5版)
- R語言游戲數(shù)據(jù)分析與挖掘
- ASP.NET 3.5程序設(shè)計(jì)與項(xiàng)目實(shí)踐
- QGIS By Example
- Python編程:從入門到實(shí)踐
- Angular開發(fā)入門與實(shí)戰(zhàn)
- 區(qū)塊鏈底層設(shè)計(jì)Java實(shí)戰(zhàn)
- Essential C++(中文版)
- 動手打造深度學(xué)習(xí)框架
- 并行編程方法與優(yōu)化實(shí)踐
- 從程序員角度學(xué)習(xí)數(shù)據(jù)庫技術(shù)(藍(lán)橋杯軟件大賽培訓(xùn)教材-Java方向)
- HTML+CSS+JavaScript網(wǎng)頁制作:從入門到精通(第4版)