How To Use The Find Function In Underscore JS

How To Use The Find Function In Underscore JS

The find() function is another very commonly used function in the Underscore JavaScript Library. The signature has a familiar look in _.find(list, predicate, [context]) similar to the some() function we recently covered. The find() function takes an array or object as the first parameter. The second parameter is a required function that must be passed which runs against each element in the array element or object property that was passed in as the first argument.…

Underscore JS Some Function

underscore js some function

In this ongoing look at Underscore JS, we’ll take a look at the some function. It bears a close resemblance to the find function. The some function has a signature of _.some(list, [predicate], [context]). What it does is to scan the list parameter for any items that contain a truthy value and return true if this is the case. This is the default behavior without passing the optional predicate function.…

Underscore JS Each Function

Underscore JS Each Function

As we mentioned, the various collection functions in Underscore really help us to navigate our way around JavaScript objects and arrays in a really easy and straightforward way. In this particular tutorial we’ll have a look at the each function and how we can use it with arrays, objects, arrays with context, as well as objects with context. When we say with context, all we really mean is what the this keyword will be pointing to during particular portions of code execution.…

Underscore JS Map Function

Underscore JS Collection Functions

Underscore.js is the widely popular JavaScript library that provides a rich set of utility functions for working with the JavaScript language. Unlike PHP, JavaScript does not have thousands and thousands of built in functions to make working with data easier. Underscore fixes this by providing various functions that make it easier to deal with JavaScript Objects, Arrays, and Functions. Underscore.js is typically included in projects to offer an approach to coding in JavaScript that is both easier and more expressive than you would find with native JavaScript.…

JavaScript Revealing Prototype Pattern

JavaScript Revealing Prototype Pattern

The Revealing Prototype Pattern makes use of two of the patterns we have covered already. It takes the concepts of both the revealing module pattern and the prototype pattern and merges the best of those patterns together. The result is a pattern that offers a lot to the developer and works well for both creating libraries or for custom code in a particular use case. The Revealing Prototype Pattern provides encapsulation and facilitates developers to modularize their code instead of having a mess of functions just randomly strewn about a project.…