Dependent Library underscore
Underscore library is the only dependent library of backbone, the following from five aspects of the underscore library processing sets, arrays, functions, objects, functions of the main functions of the various types of use;
- Collection
each ()/map () function: iterates through each element of the set according to certain conditions;
Each_.each (list, iteratee, [context]) Alias:foreach:
Map_.map (list, iteratee, [context]) Alias:collect
Find ()/filter () function: Find or filter functions, in the specified list and object, look for elements that conform to the custom function rules in the iteratee iterator;
_.find (list, predicate,[context]) alias:detect
_.filter (list, predicate,[context]) alias:select
Max ()/min (): Returns the maximum and minimum values of the list;
_.max (list, [Iteratee],[context])
_.min (list, [iteratee], [context])
SortBy (), GroupBy (): Sorting and Grouping lists or objects
_.sortby (list, Iteratee,[context])
_.groupby (list, Iteratee,[context])
- Array
First ()/last () Gets the initial or last element in the array, or the preceding or subsequent array of the specified number of digits
_.first (array, [n]) Alias:head, take
_.last (array, [n])
Iindexof ()/lastindexof (): Finds if an element exists in the array
_.indexof (array, value,[issorted])
_.lastindexof (array, Value,[fromindex])
Without ()/union (): Excludes some or more groups in the array from being linked
_.without (array, *values)
_.union (*arrays)
- Function
Delay (): Segment code or a function deferred execution
_.delay (function, wait,*arguments)
Once (): Creates a function that can only be called once.
_.once (function)
Wrap (): Wraps the function itself into a wraper (wrapper outer layer), encapsulates the first function functions into the function wrapper, and passes the function functions as the first argument to wrapper. This allows the wrapper to execute the code before and after the function runs, adjusting the parameters and then performing them conditionally.
_.wrap (function, wrapper)
Compose (): Used to calculate some of the more complex operations in mathematics, return function set functions composite function, that is, after the execution of one of the functions, the returned result is assigned to the next function as a parameter to execute. And so on. In mathematics, the function f (), g (), and H () can be combined to obtain a composite function f (g (H ())).
_.compose (*functions)
- Object
Keys ()/values (): Used to return the property name and value of an object
_.keys (object)
_.values ({one:1, two:2, three:3});
Pick ()/omit (): Returns white list and non-blacklisted objects
_.pick (object, *keys)
_.omit (object, *keys)
Defaults (): Set object default property value, reset property, default value does not work
_.defaults (object, *defaults)
Has (): Returns whether the object collection contains the specified key value, contains a return of true, otherwise returns false
_.has (object, key)
- Function
Random (): Returns the number in the specified range, and if you pass only one argument, the integer between 0 and this parameter is returned.
_.random (min, max)
Escape ()/unescape (): HTML will encode and string escape;
_.escape (String)
_.unescape (' Curly, larry& Moe ')
Template () compiles the contents of the page module
_.template (Templatestring,[settings])
Chain (): Returns an object that can be chained, returning an encapsulated object. Calling a method on a encapsulated object returns the encapsulated object itself, straight until the value method call.
_.chain (obj)
Backbone sole Dependent Library Underscore.js