

The pleasure of making a daisy-chain would be worth the trouble \ So she was considering in her own mind (as well as she could, \įor the hot day made her feel very sleepy and stupid), whether \ 'and what is the use of a book,' thought Alice \ Or twice she had peeped into the book her sister was reading, \īut it had no pictures or conversations in it, \ Var text = "Alice was beginning to get very tired of sitting \īy her sister on the bank, and of having nothing to do: once \

This is what our first attempt at solving the problem might look like if we never heard of functional programming in general and Underscore.js and corresponding JavaScript APIs in particular. Let’s say that as part of some other larger project we would like to write code that analyzes text and outputs some important information like the list of all the used words in the alphabetical order, the top 10 most frequently used words, the total number of words, etc. Because, who knows maybe we don’t need Underscore.js at all and you can already stop reading the article? We will see what problems we may have and that it actually solves them well. O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.Before looking at Underscore.js more closely let’s first discuss the context in which it can be useful. Get Mastering JavaScript Single Page Application Development now with the O’Reilly learning platform. The _.template() method can also be used to parse and execute arbitrary JavaScript code within a template. The variable name would be dynamically passed in to the compiled function for this template. Īn Underscore.js template expression used within HTML looks like the preceding example. Underscore.js template syntax delimiters resemble those of the ERB, or Embedded Ruby template syntax, with an equals sign following the opening tag: Hello. This method is used to compile strings with expressions into functions that replace those expressions with dynamic values. One of those utility methods is _.template(). The Underscore.js library is well known for its useful JavaScript functional programming helpers and utility methods.
