rest_.rest(array, [index]) Alias: tail, drop Returns the rest of the elements in an array. Pass an index to return the values of the array from that index onward. _.rest([5, 4, 3, 2, 1]); => [4, 3, 2, 1]
difference_.difference(array, *others) Similar to without, but returns the values from array that are not present in the other arrays. _.difference([1, 2, 3, 4, 5], [5, 2, 10]); => [1, 3, 4]
defaults_.defaults(object, *defaults) Fill in undefined properties in object with the first value present in the following list of defaults objects. var iceCream = {flavor: "chocolate"}; _.defaults(iceCream, {flavor: "vanilla", sprinkles: "lots"}); => {flavor: "chocolate", sprinkles: "lots"}
create_.create(prototype, props) Creates a new object with the given prototype, optionally attaching props as own properties. Basically, Object.create, but without all of the property descriptor jazz. var moe = _.create(Stooge.prototype, {name: "Moe"});
delay_.delay(function, wait, *arguments) Much like setTimeout, invokes function after wait milliseconds. If you pass the optional arguments, they will be forwarded on to the function when it is invoked. var log = _.bind(console.log, console); _.delay(log, 1000, 'logged later'); => 'logged later' // Appears after one second.
defer_.defer(function, *arguments) Defers invoking the function until the current call stack has cleared, similar to using setTimeout with a delay of 0. Useful for performing expensive computations or HTML rendering in chunks without blocking the UI thread from updating. If you pass the optional arguments, they will be forwarded on to the function when it is invoked. _.defer(function(){ alert('deferred'); }); // Returns from the function before the alert runs.
debounce_.debounce(function, wait, [immediate]) Creates and returns a new debounced version of the passed function which will postpone its execution until after wait milliseconds have elapsed since the last time it was invoked. Useful for implementing behavior that should only happen after the input has stopped arriving. For example: rendering a preview of a Markdown comment, recalculating a layout after the window has stopped being resized, and so on. At the end of the wait interval, the f
compose_.compose(*functions) Returns the composition of a list of functions, where each function consumes the return value of the function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())). var greet = function(name){ return "hi: " + name; }; var exclaim = function(statement){ return statement.toUpperCase() + "!"; }; var welcome = _.compose(greet, exclaim); welcome('moe'); => 'hi: MOE!'
constant_.constant(value) Creates a function that returns the same value that is used as the argument of _.constant. var stooge = {name: 'moe'}; stooge === _.constant(stooge)(); => true
contains_.contains(list, value, [fromIndex]) Alias: includes Returns true if the value is present in the list. Uses indexOf internally, if list is an Array. Use fromIndex to start your search at a given index. _.contains([1, 2, 3], 3); => true
Page 10 of 12