Backbone sole Dependent Library Underscore.js

Source: Internet
Author: User

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;

    1. 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])

    1. 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)

    1. 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)

    1. 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)

    1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.