NIM4IE7.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. (function () {
  2. // Object.keys
  3. (function () {
  4. if (!Object.keys) {
  5. Object.keys = (function () {
  6. 'use strict';
  7. var hasOwnProperty = Object.prototype.hasOwnProperty,
  8. hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),
  9. dontEnums = [
  10. 'toString',
  11. 'toLocaleString',
  12. 'valueOf',
  13. 'hasOwnProperty',
  14. 'isPrototypeOf',
  15. 'propertyIsEnumerable',
  16. 'constructor'
  17. ],
  18. dontEnumsLength = dontEnums.length;
  19. return function (obj) {
  20. if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
  21. throw new TypeError('Object.keys called on non-object');
  22. }
  23. var result = [], prop, i;
  24. for (prop in obj) {
  25. if (hasOwnProperty.call(obj, prop)) {
  26. result.push(prop);
  27. }
  28. }
  29. if (hasDontEnumBug) {
  30. for (i = 0; i < dontEnumsLength; i++) {
  31. if (hasOwnProperty.call(obj, dontEnums[i])) {
  32. result.push(dontEnums[i]);
  33. }
  34. }
  35. }
  36. return result;
  37. };
  38. }());
  39. }
  40. })();
  41. if (!Array.prototype.map) {
  42. Array.prototype.map = function (callback, thisArg) {
  43. var T, A, k;
  44. if (this == null) {
  45. throw new TypeError(" this is null or not defined");
  46. }
  47. // 1. Let O be the result of calling ToObject passing the |this|
  48. // value as the argument.
  49. var O = Object(this);
  50. // 2. Let lenValue be the result of calling the Get internal
  51. // method of O with the argument "length".
  52. // 3. Let len be ToUint32(lenValue).
  53. var len = O.length >>> 0;
  54. // 4. If IsCallable(callback) is false, throw a TypeError exception.
  55. // See: http://es5.github.com/#x9.11
  56. if (typeof callback !== "function") {
  57. throw new TypeError(callback + " is not a function");
  58. }
  59. // 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
  60. if (arguments.length > 1) {
  61. T = thisArg;
  62. }
  63. // 6. Let A be a new array created as if by the expression new Array(len)
  64. // where Array is the standard built-in constructor with that name and
  65. // len is the value of len.
  66. A = new Array(len);
  67. // 7. Let k be 0
  68. k = 0;
  69. // 8. Repeat, while k < len
  70. while (k < len) {
  71. var kValue, mappedValue;
  72. // a. Let Pk be ToString(k).
  73. // This is implicit for LHS operands of the in operator
  74. // b. Let kPresent be the result of calling the HasProperty internal
  75. // method of O with argument Pk.
  76. // This step can be combined with c
  77. // c. If kPresent is true, then
  78. if (k in O) {
  79. // i. Let kValue be the result of calling the Get internal
  80. // method of O with argument Pk.
  81. kValue = O[k];
  82. // ii. Let mappedValue be the result of calling the Call internal
  83. // method of callback with T as the this value and argument
  84. // list containing kValue, k, and O.
  85. mappedValue = callback.call(T, kValue, k, O);
  86. // iii. Call the DefineOwnProperty internal method of A with arguments
  87. // Pk, Property Descriptor
  88. // { Value: mappedValue,
  89. // Writable: true,
  90. // Enumerable: true,
  91. // Configurable: true },
  92. // and false.
  93. // In browsers that support Object.defineProperty, use the following:
  94. // Object.defineProperty(A, k, {
  95. // value: mappedValue,
  96. // writable: true,
  97. // enumerable: true,
  98. // configurable: true
  99. // });
  100. // For best browser support, use the following:
  101. A[k] = mappedValue;
  102. }
  103. // d. Increase k by 1.
  104. k++;
  105. }
  106. // 9. return A
  107. return A;
  108. };
  109. }
  110. if (!Array.prototype.forEach) {
  111. Array.prototype.forEach = function (callback, thisArg) {
  112. var T, k;
  113. if (this == null) {
  114. throw new TypeError(' this is null or not defined');
  115. }
  116. // 1. Let O be the result of calling ToObject passing the |this| value as the argument.
  117. var O = Object(this);
  118. // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
  119. // 3. Let len be ToUint32(lenValue).
  120. var len = O.length >>> 0;
  121. // 4. If IsCallable(callback) is false, throw a TypeError exception.
  122. // See: http://es5.github.com/#x9.11
  123. if (typeof callback !== "function") {
  124. throw new TypeError(callback + ' is not a function');
  125. }
  126. // 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
  127. if (arguments.length > 1) {
  128. T = thisArg;
  129. }
  130. // 6. Let k be 0
  131. k = 0;
  132. // 7. Repeat, while k < len
  133. while (k < len) {
  134. var kValue;
  135. // a. Let Pk be ToString(k).
  136. // This is implicit for LHS operands of the in operator
  137. // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
  138. // This step can be combined with c
  139. // c. If kPresent is true, then
  140. if (k in O) {
  141. // i. Let kValue be the result of calling the Get internal method of O with argument Pk.
  142. kValue = O[k];
  143. // ii. Call the Call internal method of callback with T as the this value and
  144. // argument list containing kValue, k, and O.
  145. callback.call(T, kValue, k, O);
  146. }
  147. // d. Increase k by 1.
  148. k++;
  149. }
  150. // 8. return undefined
  151. };
  152. }
  153. if (!Array.prototype.indexOf) {
  154. Array.prototype.indexOf = function(searchElement, fromIndex) {
  155. var k;
  156. // 1. Let O be the result of calling ToObject passing
  157. // the this value as the argument.
  158. if (this == null) {
  159. throw new TypeError('"this" is null or not defined');
  160. }
  161. var O = Object(this);
  162. // 2. Let lenValue be the result of calling the Get
  163. // internal method of O with the argument "length".
  164. // 3. Let len be ToUint32(lenValue).
  165. var len = O.length >>> 0;
  166. // 4. If len is 0, return -1.
  167. if (len === 0) {
  168. return -1;
  169. }
  170. // 5. If argument fromIndex was passed let n be
  171. // ToInteger(fromIndex); else let n be 0.
  172. var n = +fromIndex || 0;
  173. if (Math.abs(n) === Infinity) {
  174. n = 0;
  175. }
  176. // 6. If n >= len, return -1.
  177. if (n >= len) {
  178. return -1;
  179. }
  180. // 7. If n >= 0, then Let k be n.
  181. // 8. Else, n<0, Let k be len - abs(n).
  182. // If k is less than 0, then let k be 0.
  183. k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
  184. // 9. Repeat, while k < len
  185. while (k < len) {
  186. var kValue;
  187. // a. Let Pk be ToString(k).
  188. // This is implicit for LHS operands of the in operator
  189. // b. Let kPresent be the result of calling the
  190. // HasProperty internal method of O with argument Pk.
  191. // This step can be combined with c
  192. // c. If kPresent is true, then
  193. // i. Let elementK be the result of calling the Get
  194. // internal method of O with the argument ToString(k).
  195. // ii. Let same be the result of applying the
  196. // Strict Equality Comparison Algorithm to
  197. // searchElement and elementK.
  198. // iii. If same is true, return k.
  199. if (k in O && O[k] === searchElement) {
  200. return k;
  201. }
  202. k++;
  203. }
  204. return -1;
  205. };
  206. }
  207. })();