[ Pobierz całość w formacie PDF ]
the following properties:
15.4.3.1 Array.prototype
The initial value ofArray.prototypeis the Array prototype object (15.4.4).
This property has the attributes { DontEnum, DontDelete, ReadOnly }.
15.4.4 Properties of the Array Prototype Object
The value of the internal [[Prototype]] property of the Array prototype object is the Object prototype
object (15.2.3.1).
The Array prototype object is itself an array; its [[Class]] is"Array", and it has alengthproperty
(whose initial value is +0) and the special internal [[Put]] method described in 15.2.3.1.
In following descriptions of functions that are properties of the Array prototype object, the phrase this
object refers to the object that is the this value for the invocation of the function. It is permitted for the
this to be an object for which the value of the internal [[Class]] property is not"Array".
NOTE
The Array prototype object does not have avalueOfproperty of its own; however, it inherits the
valueOfproperty from the Object prototype Object.
15.4.4.1 Array.prototype.constructor
The initial value ofArray.prototype.constructoris the built-inArrayconstructor.
15.4.4.2 Array.prototype.toString ( )
The result of calling this function is the same as if the built-injoinmethod were invoked for this
object with no argument.
ThetoStringfunction is not generic; it throws a TypeError exception if its this value is not an
Array object. Therefore, it cannot be transferred to other kinds of objects for use as a method.
15.4.4.3 Array.prototype.toLocaleString ( )
The elements of the array are converted to strings using theirtoLocaleStringmethods, and these
strings are then concatenated, separated by occurrences of a separator string that has been derived in
an implementation-defined locale-specific way. The result of calling this function is intended to be
analogous to the result oftoString, except that the result of this function is intended to be locale-
specific.
The result is calculated as follows:
1. Call the [[Get]] method of this object with argument"length".
2. Call ToUint32(Result(1)).
3. Let separator be the list-separator string appropriate for the host environment s current locale
(this is derived in an implementation-defined way).
- 90 -
4. Call ToString(separator).
5. If Result(2) is zero, return the empty string.
6. Call the [[Get]] method of this object with argument"0".
7. If Result(6) is undefined or null, use the empty string; otherwise, call
ToObject(Result(6)).toLocaleString().
8. Let R be Result(7).
9. Let k be1.
10. If k equals Result(2), return R.
11. Let S be a string value produced by concatenating R and Result(4).
12. Call the [[Get]] method of this object with argument ToString(k).
13. If Result(12) is undefined or null, use the empty string; otherwise, call
ToObject(Result(12)).toLocaleString().
14. Let R be a string value produced by concatenating S and Result(13).
15. Increase k by 1.
16. Go to step 10.
ThetoLocaleStringfunction is not generic; it throws a TypeError exception if its this value is
not an Array object. Therefore, it cannot be transferred to other kinds of objects for use as a method.
NOTE
The first parameter to this function is likely to be used in a future version of this standard; it is
recommended that implementations do not use this parameter position for anything else.
15.4.4.4 Array.prototype.concat ( [ item1 [ , item2 [ , & ] ] ] )
When theconcatmethod is called with zero or more arguments item1, item2, etc., it returns an array
containing the array elements of the object followed by the array elements of each argument in order.
The following steps are taken:
1. Let A be a new array created as if by the expressionnew Array().
2. Let n be 0.
3. Let E be this object.
4. If E is not an Array object, go to step 16.
5. Let k be 0.
6. Call the [[Get]] method of E with argument"length".
7. If k equals Result(6) go to step 19.
8. Call ToString(k).
9. If E has a property named by Result(8), go to step 10, but if E has no property named by
Result(8), go to step 13.
10. Call ToString(n).
11. Call the [[Get]] method of E with argument Result(8).
12. Call the [[Put]] method of A with arguments Result(10) and Result(11).
13. Increase n by 1.
14. Increase k by 1.
15. Go to step 7.
16. Call ToString(n).
17. Call the [[Put]] method of A with arguments Result(16) and E.
18. Increase n by 1.
19. Get the next argument in the argument list; if there are no more arguments, go to step 22.
20. Let E be Result(19).
21. Go to step 4.
22. Call the [[Put]] method of A with arguments"length"and n.
23. Return A.
Thelengthproperty of theconcatmethod is 1.
- 91 -
NOTE
Theconcatfunction is intentionally generic; it does not require that its this value be an Array
object. Therefore it can be transferred to other kinds of objects for use as a method. Whether the
concatfunction can be applied successfully to a host object is implementation-dependent.
15.4.4.5 Array.prototype.join (separator)
The elements of the array are converted to strings, and these strings are then concatenated, separated
by occurrences of the separator. If no separator is provided, a single comma is used as the separator.
Thejoinmethod takes one argument, separator, and performs the following steps:
1. Call the [[Get]] method of this object with argument"length".
2. Call ToUint32(Result(1)).
3. If separator is undefined, let separator be the single-character string",".
4. Call ToString(separator).
5. If Result(2) is zero, return the empty string.
6. Call the [[Get]] method of this object with argument"0".
7. If Result(6) is undefined or null, use the empty string; otherwise, call ToString(Result(6)).
8. Let R be Result(7).
9. Let k be1.
10. If k equals Result(2), return R.
11. Let S be a string value produced by concatenating R and Result(4).
12. Call the [[Get]] method of this object with argument ToString(k).
13. If Result(12) is undefined or null, use the empty string; otherwise, call ToString(Result(12)).
14. Let R be a string value produced by concatenating S and Result(13).
15. Increase k by 1.
16. Go to step 10.
Thelengthproperty of thejoinmethod is 1.
NOTE
Thejoinfunction is intentionally generic; it does not require that its this value be an Array object.
Therefore, it can be transferred to other kinds of objects for use as a method. Whether thejoin
function can be applied successfully to a host object is implementation-dependent.
15.4.4.6 Array.prototype.pop ( )
The last element of the array is removed from the array and returned.
1. Call the [[Get]] method of this object with argument"length".
2. Call ToUint32(Result(1)).
3. If Result(2) is not zero, go to step 6.
4. Call the [[Put]] method of this object with arguments"length"and Result(2).
5. Return undefined.
6. Call ToString(Result(2) 1).
7. Call the [[Get]] method of this object with argument Result(6).
8. Call the [[Delete]] method of this object with argument Result(6).
9. Call the [[Put]] method of this object with arguments"length"and (Result(2) 1).
10. Return Result(7).
NOTE
Thepopfunction is intentionally generic; it does not require that its this value be an Array object.
Therefore it can be transferred to other kinds of objects for use as a method. Whether the pop
function can be applied successfully to a host object is implementation-dependent.
15.4.4.7 Array.prototype.push ( [ item1 [ , item2 [ , & ] ] ] )
The arguments are appended to the end of the array, in the order in which they appear. The new length
[ Pobierz całość w formacie PDF ]