Function

_.after

❗️Note this is an alternative implementationCreates a version of the function that will only be run after first being called count times. Useful for grouping asynchronous responses, where you want to be sure that all the async calls have finished, before proceeding.

  1. var notes = ['profile', 'settings']
  2. // Underscore/Lodash
  3. var renderNotes = _.after(notes.length, render)
  4. notes.forEach(function (note) {
  5. console.log(note)
  6. renderNotes()
  7. })
  8.  
  9. // Native
  10. notes.forEach(function (note, index) {
  11. console.log(note)
  12. if (notes.length === (index + 1)) {
  13. render()
  14. }
  15. })

Browser Support for Array.prototype.forEach()

ChromeEdgeFirefoxIEOperaSafari
1.5 ✔9.0 ✔

_.bind

Create a new function that calls func with thisArg and args.

  1. var objA = {
  2. x: 66,
  3. offsetX: function(offset) {
  4. return this.x + offset;
  5. }
  6. }
  7.  
  8. var objB = {
  9. x: 67
  10. };
  11.  
  12. // Underscore/Lodash
  13. var boundOffsetX = _.bind(objA.offsetX, objB, 0);
  14.  
  15. // Native
  16. var boundOffsetX = objA.offsetX.bind(objB, 0);

Browser Support for Function.prototype.bind()

ChromeEdgeFirefoxIEOperaSafari
7.0 ✔4.0 ✔9.0 ✔11.6 ✔5.1 ✔

_.partial

Create a new function that calls func with args.

  1. // Lodash
  2. function greet(greeting, name) {
  3. return greeting + ' ' + name;
  4. }
  5. var sayHelloTo = _.partial(greet, 'Hello');
  6. var result = sayHelloTo('Jose')
  7. console.log(result)
  8. // output: 'Hello Jose'
  9.  
  10. // Native
  11. function greet(greeting, name) {
  12. return greeting + ' ' + name;
  13. }
  14. var sayHelloTo = (...args) => greet('Hello', ...args)
  15. var result = sayHelloTo('Jose')
  16. console.log(result)
  17. // output: 'Hello Jose'

Browser Support for Spread

ChromeEdgeFirefoxIEOperaSafari
46.0 ✔12.0 ✔16.0 ✔37.0 ✔8.0 ✔