|
99 | 99 | return dec; |
100 | 100 | }; |
101 | 101 | } |
102 | | - |
103 | | - if (!Array.prototype.map) { |
104 | | - Array.prototype.map = function(fun /*, thisArg */) { |
105 | | - if (this === void 0 || this === null || typeof fun !== "function") |
| 102 | + |
| 103 | + if (!Array.prototype.map) { |
| 104 | + Array.prototype.map = function(fun /*, thisArg */) { |
| 105 | + if (this === void 0 || this === null || typeof fun !== "function") |
106 | 106 | throw new TypeError(); |
107 | | - |
108 | | - var t = Object(this), len = t.length >>> 0, res = new Array(len); |
109 | | - var thisArg = arguments.length > 1 ? arguments[1] : void 0; |
110 | | - for (var i = 0; i < len; i++) { |
111 | | - // NOTE: Absolute correctness would demand Object.defineProperty |
112 | | - // be used. But this method is fairly new, and failure is |
113 | | - // possible only if Object.prototype or Array.prototype |
114 | | - // has a property |i| (very unlikely), so use a less-correct |
115 | | - // but more portable alternative. |
116 | | - if (i in t) |
117 | | - res[i] = fun.call(thisArg, t[i], i, t); |
| 107 | + |
| 108 | + var t = Object(this), len = t.length >>> 0, res = new Array(len); |
| 109 | + var thisArg = arguments.length > 1 ? arguments[1] : void 0; |
| 110 | + for (var i = 0; i < len; i++) { |
| 111 | + // NOTE: Absolute correctness would demand Object.defineProperty |
| 112 | + // be used. But this method is fairly new, and failure is |
| 113 | + // possible only if Object.prototype or Array.prototype |
| 114 | + // has a property |i| (very unlikely), so use a less-correct |
| 115 | + // but more portable alternative. |
| 116 | + if (i in t) |
| 117 | + res[i] = fun.call(thisArg, t[i], i, t); |
118 | 118 | } |
119 | | - |
120 | | - return res; |
121 | | - }; |
| 119 | + |
| 120 | + return res; |
| 121 | + }; |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | + if(!Array.isArray) { |
| 126 | + Array.isArray = function(arg) { |
| 127 | + return Object.prototype.toString.call(arg) === '[object Array]'; |
| 128 | + }; |
122 | 129 | } |
123 | 130 |
|
124 | 131 | if (!Array.prototype.forEach) { |
|
135 | 142 | } |
136 | 143 | }; |
137 | 144 | } |
138 | | - |
139 | | - if (!Object.keys) { |
140 | | - Object.keys = (function () { |
| 145 | + |
| 146 | + if (!Object.keys) { |
| 147 | + Object.keys = (function () { |
141 | 148 | 'use strict'; |
142 | | - |
143 | | - var hasOwnProperty = Object.prototype.hasOwnProperty, |
144 | | - hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'), |
145 | | - dontEnums = ['toString','toLocaleString','valueOf','hasOwnProperty', |
146 | | - 'isPrototypeOf','propertyIsEnumerable','constructor'], |
| 149 | + |
| 150 | + var hasOwnProperty = Object.prototype.hasOwnProperty, |
| 151 | + hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'), |
| 152 | + dontEnums = ['toString','toLocaleString','valueOf','hasOwnProperty', |
| 153 | + 'isPrototypeOf','propertyIsEnumerable','constructor'], |
147 | 154 | dontEnumsLength = dontEnums.length; |
148 | | - |
149 | | - return function (obj) { |
150 | | - if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) { |
151 | | - throw new TypeError(); |
152 | | - } |
| 155 | + |
| 156 | + return function (obj) { |
| 157 | + if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) { |
| 158 | + throw new TypeError(); |
| 159 | + } |
153 | 160 | var result = [], prop, i; |
154 | | - |
155 | | - for (prop in obj) { |
156 | | - if (hasOwnProperty.call(obj, prop)) { |
157 | | - result.push(prop); |
158 | | - } |
| 161 | + |
| 162 | + for (prop in obj) { |
| 163 | + if (hasOwnProperty.call(obj, prop)) { |
| 164 | + result.push(prop); |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + if (hasDontEnumBug) { |
| 169 | + for (i = 0; i < dontEnumsLength; i++) { |
| 170 | + if (hasOwnProperty.call(obj, dontEnums[i])) { |
| 171 | + result.push(dontEnums[i]); |
| 172 | + } |
| 173 | + } |
159 | 174 | } |
160 | | - |
161 | | - if (hasDontEnumBug) { |
162 | | - for (i = 0; i < dontEnumsLength; i++) { |
163 | | - if (hasOwnProperty.call(obj, dontEnums[i])) { |
164 | | - result.push(dontEnums[i]); |
165 | | - } |
166 | | - } |
167 | | - } |
168 | | - return result; |
169 | | - }; |
170 | | - }()); |
| 175 | + return result; |
| 176 | + }; |
| 177 | + }()); |
171 | 178 | } |
172 | 179 |
|
173 | | - if (!String.prototype.trim) { |
174 | | - String.prototype.trim = function () { |
175 | | - return this.replace(/^\s+|\s+$/g, ''); |
176 | | - }; |
177 | | - } |
178 | | - if (!String.prototype.trimLeft) { |
179 | | - String.prototype.trimLeft = function() { |
180 | | - return this.replace(/^\s+/g, ""); |
181 | | - }; |
182 | | - } |
183 | | - if (!String.prototype.trimRight) { |
184 | | - String.prototype.trimRight = function() { |
185 | | - return this.replace(/\s+$/g, ""); |
186 | | - }; |
| 180 | + if (!String.prototype.trim) { |
| 181 | + String.prototype.trim = function () { |
| 182 | + return this.replace(/^\s+|\s+$/g, ''); |
| 183 | + }; |
| 184 | + } |
| 185 | + if (!String.prototype.trimLeft) { |
| 186 | + String.prototype.trimLeft = function() { |
| 187 | + return this.replace(/^\s+/g, ""); |
| 188 | + }; |
187 | 189 | } |
188 | | - |
| 190 | + if (!String.prototype.trimRight) { |
| 191 | + String.prototype.trimRight = function() { |
| 192 | + return this.replace(/\s+$/g, ""); |
| 193 | + }; |
| 194 | + } |
| 195 | + |
189 | 196 | })(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this); |
0 commit comments