|
1 | | -// Production steps of ECMA-262, Edition 5, 15.4.4.18 |
2 | | -// Reference: http://es5.github.io/#x15.4.4.18 |
3 | | -if (!Array.prototype.forEach) { |
4 | | - |
5 | | - Array.prototype.forEach = function(callback, thisArg) { |
6 | | - |
7 | | - var T, k; |
8 | | - |
9 | | - if (this == null) { |
10 | | - throw new TypeError(" this is null or not defined"); |
11 | | - } |
12 | | - |
13 | | - // 1. Let O be the result of calling ToObject passing the |this| value as the argument. |
14 | | - var O = Object(this); |
15 | | - |
16 | | - // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length". |
17 | | - // 3. Let len be ToUint32(lenValue). |
18 | | - var len = O.length >>> 0; |
19 | | - |
20 | | - // 4. If IsCallable(callback) is false, throw a TypeError exception. |
21 | | - // See: http://es5.github.com/#x9.11 |
22 | | - if (typeof callback !== "function") { |
23 | | - throw new TypeError(callback + " is not a function"); |
24 | | - } |
25 | | - |
26 | | - // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. |
27 | | - if (arguments.length > 1) { |
28 | | - T = thisArg; |
29 | | - } |
30 | | - |
31 | | - // 6. Let k be 0 |
32 | | - k = 0; |
33 | | - |
34 | | - // 7. Repeat, while k < len |
35 | | - while (k < len) { |
36 | | - |
37 | | - var kValue; |
38 | | - |
39 | | - // a. Let Pk be ToString(k). |
40 | | - // This is implicit for LHS operands of the in operator |
41 | | - // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk. |
42 | | - // This step can be combined with c |
43 | | - // c. If kPresent is true, then |
44 | | - if (k in O) { |
45 | | - |
46 | | - // i. Let kValue be the result of calling the Get internal method of O with argument Pk. |
47 | | - kValue = O[k]; |
48 | | - |
49 | | - // ii. Call the Call internal method of callback with T as the this value and |
50 | | - // argument list containing kValue, k, and O. |
51 | | - callback.call(T, kValue, k, O); |
52 | | - } |
53 | | - // d. Increase k by 1. |
54 | | - k++; |
55 | | - } |
56 | | - // 8. return undefined |
57 | | - }; |
58 | | -} |
59 | | - |
60 | | -// Production steps of ECMA-262, Edition 5, 15.4.4.19 |
61 | | -// Reference: http://es5.github.io/#x15.4.4.19 |
62 | | -if (!Array.prototype.map) { |
63 | | - |
64 | | - Array.prototype.map = function(callback, thisArg) { |
65 | | - |
66 | | - var T, A, k; |
67 | | - |
68 | | - if (this == null) { |
69 | | - throw new TypeError(" this is null or not defined"); |
70 | | - } |
71 | | - |
72 | | - // 1. Let O be the result of calling ToObject passing the |this| |
73 | | - // value as the argument. |
74 | | - var O = Object(this); |
75 | | - |
76 | | - // 2. Let lenValue be the result of calling the Get internal |
77 | | - // method of O with the argument "length". |
78 | | - // 3. Let len be ToUint32(lenValue). |
79 | | - var len = O.length >>> 0; |
80 | | - |
81 | | - // 4. If IsCallable(callback) is false, throw a TypeError exception. |
82 | | - // See: http://es5.github.com/#x9.11 |
83 | | - if (typeof callback !== "function") { |
84 | | - throw new TypeError(callback + " is not a function"); |
85 | | - } |
86 | | - |
87 | | - // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. |
88 | | - if (arguments.length > 1) { |
89 | | - T = thisArg; |
90 | | - } |
91 | | - |
92 | | - // 6. Let A be a new array created as if by the expression new Array(len) |
93 | | - // where Array is the standard built-in constructor with that name and |
94 | | - // len is the value of len. |
95 | | - A = new Array(len); |
96 | | - |
97 | | - // 7. Let k be 0 |
98 | | - k = 0; |
99 | | - |
100 | | - // 8. Repeat, while k < len |
101 | | - while (k < len) { |
102 | | - |
103 | | - var kValue, mappedValue; |
104 | | - |
105 | | - // a. Let Pk be ToString(k). |
106 | | - // This is implicit for LHS operands of the in operator |
107 | | - // b. Let kPresent be the result of calling the HasProperty internal |
108 | | - // method of O with argument Pk. |
109 | | - // This step can be combined with c |
110 | | - // c. If kPresent is true, then |
111 | | - if (k in O) { |
112 | | - |
113 | | - // i. Let kValue be the result of calling the Get internal |
114 | | - // method of O with argument Pk. |
115 | | - kValue = O[k]; |
116 | | - |
117 | | - // ii. Let mappedValue be the result of calling the Call internal |
118 | | - // method of callback with T as the this value and argument |
119 | | - // list containing kValue, k, and O. |
120 | | - mappedValue = callback.call(T, kValue, k, O); |
121 | | - |
122 | | - // iii. Call the DefineOwnProperty internal method of A with arguments |
123 | | - // Pk, Property Descriptor |
124 | | - // { Value: mappedValue, |
125 | | - // Writable: true, |
126 | | - // Enumerable: true, |
127 | | - // Configurable: true }, |
128 | | - // and false. |
129 | | - |
130 | | - // In browsers that support Object.defineProperty, use the following: |
131 | | - // Object.defineProperty(A, k, { |
132 | | - // value: mappedValue, |
133 | | - // writable: true, |
134 | | - // enumerable: true, |
135 | | - // configurable: true |
136 | | - // }); |
137 | | - |
138 | | - // For best browser support, use the following: |
139 | | - A[k] = mappedValue; |
140 | | - } |
141 | | - // d. Increase k by 1. |
142 | | - k++; |
143 | | - } |
144 | | - |
145 | | - // 9. return A |
146 | | - return A; |
147 | | - }; |
148 | | -} |
149 | | - |
150 | | -if (!Array.isArray) { |
151 | | - Array.isArray = function(arg) { |
152 | | - return Object.prototype.toString.call(arg) === "[object Array]"; |
153 | | - }; |
154 | | -} |
155 | | - |
156 | | - |
157 | | -if (!String.prototype.endsWith) { |
158 | | - String.prototype.endsWith = function(searchString, position) { |
159 | | - var subjectString = this.toString(); |
160 | | - if (position === undefined || position > subjectString.length) { |
161 | | - position = subjectString.length; |
162 | | - } |
163 | | - position -= searchString.length; |
164 | | - var lastIndex = subjectString.indexOf(searchString, position); |
165 | | - return lastIndex !== -1 && lastIndex === position; |
166 | | - }; |
167 | | -} |
168 | | - |
169 | 1 | // http://paulirish.com/2011/requestanimationframe-for-smart-animating/ |
170 | 2 | // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating |
171 | 3 | // requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel |
|
0 commit comments