Enumerable is an abstract object (it should be noted that there is no concept of a class in JavaScript, the class is a function, and inheritance generally refers to an object (parent) copy of its Method property (through Object.extend, copy is a reference) to the subclass (function) Enumerable cannot be used directly, it is inherited by many enumerated types (Hash, Array, range, and so on), and the inherited type implements a _each method that provides a specific type of enumeration method prototype Enumerable provides the following methods for other subclasses:
Each (iterator):Iterator is a function object that invokes the _each method of a specific type to invoke iterator for each object it contains, for example, if enumerable specifically refers to a array,eg:var a=[2,3,4], A.each ( Iterator) method will call iterator (2,0), iterator (3,1), iterator (4,3), where the second parameter refers to the index. This method is used in almost every method in enumerable.
Eachslice (number, iterator):Separate each enumerable type object by number, such as [1,2,3,4,5].eachslice (3) =>[[1,2,3],[4,5]] without providing iterator, then iterator= Prototype.k:function (K) {return K},prototype many iterator default values are this, or Prototype.emptyFunction:function () {}, Actually the return is [iterator ([1,2,3]), iterator ([4,5])]
All (iterator):Call iterator for each value in the enumerable type, or false if one of them returns false, or return true, which is equivalent to determining whether each value executes iterator is "true"
Any (iterator):In contrast to all, determine whether each value is "false" (whether a value is true)
Collect (iterator)/map:Call iterator for each value, and the result is composed of a new array returned
Detect (iterator)/find:Invokes iterator for each value and, if one is not false, returns the value not to be false after the execution iterator (not the value after the execution iterator), which is equivalent to finding the first truth
FindAll (iterator)/select:Equivalent to detect, but find all the true values and return an array
grep (Pattern, iterator):Returns the value of the pattern, which, if provided by iterator, returns the value of the execution iterator
include (object)/member:Whether the array contains object
ingroupsof (number, fillwith):Variant version of Eachslice, separating the objects by number, and if the last value of the separated array is less than number, fill with fillwith, for example [1,2,3,4,5].ingroupsof (3) =>[[ 1,2,3],[4,5,null]]
inject (memo, iterator):Injection
Invoke (method):Call
Max (iterator):Maximum Value
min (iterator):Minimum value
partition (iterator):Separation
Pluck (property):Acquisition
reject (iterator):Unqualified products, contrary to FindAll
SortBy (iterator):Sort by iterator, if the object being called is array, call the built-in sort (iterator) directly.
ToArray ()/entries:Returns each value of the calling object into an array
zip ():For example [2,3,4].zip ([5,6,7]) =>[[2,5],[3,6],[4,7]], if the last parameter type is a function, it will return [iterator ([2,5]), iterator ([3,6]), Iterator ([4,7])],
Inspect ():Enumerable object string representation of Nnd, originally enumerable have so many functions, feel that the author is not learning Ruby too, what methods are moving to prototype, do we learn also hard, prototype documents also become more and more big, Wasting bandwidth ah, found that many of these functions more difficult to understand the interpretation, we still have a lot to look at the source code to understand it, my ability to express the word is really not at first glance, some really do not know how to express, I hope we still just as an informal reference, what is the problem or see the source code understanding, I wouldn't be responsible for misleading you.
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.