JavaScript Tips (@dailyjstips) profile picture
Joined December 2015
Photo by JavaScript Tips (@dailyjstips)Photo by JavaScript Tips (@dailyjstips)Photo by JavaScript Tips (@dailyjstips)Photo by JavaScript Tips (@dailyjstips)Photo by JavaScript Tips (@dailyjstips)Photo by JavaScript Tips (@dailyjstips)Photo by JavaScript Tips (@dailyjstips)Photo by JavaScript Tips (@dailyjstips)Photo by JavaScript Tips (@dailyjstips)Photo by JavaScript Tips (@dailyjstips)
Apologies to anyone following this account :)
1
In addition to the function packages, you can do custom builds of lodash to get exactly the code you need: lodash.com/custom-builds
lodash functions are packaged as individual npm modules in addition to the main library.
lodash provides functions to perform set operations like union, intersection and difference on JavaScript arrays
_.memoize creates functions that cache return values for a set of arguments to avoid re-running expensive operations
2
_.result works like _.get, but allows you to accept and evaluate functions as well. This allows for flexible apis.
1
_.get and _.set allow you to safely access and modify deeply nested properties in JavaScript objects.
1
lodash provides helpers to convert to and between camelCase, kebab-case, and snake_case.
1
_.throttle spaces out fn calls over a period of time. _.debounce limits fns to a single call within a period of time
lodash allows you to chain functions, giving you concise, clean code for data transformations
lodash provides flexible, powerful alternatives to the native functional array methods like map, reduce, and filter
The tips for this week all relate to the lodash JavaScript library. Most of them will also apply to Underscore (which lodash is a fork of)
It's possible to extract deeply nested values using destructuring. Be careful though, it can get a bit unreadable.
When destructuring objects, you can use key-value pairs to rename the variables you're extracting from an object.
Sometimes it's nice to have functions that take option objects, not a list of params. Destructuring makes that easy.
You can use destructuring to swap variable values in place. (Firefox and Safari only for right now).
ES6 introduced destructuring to JS. Destructuring allows extracting new variables from an existing object or array.
Closures are functions returned by another function that reference variables in the original function scope
1
You can wrap functions with other functions to create new modified functions. This is known as the decorator pattern