ie8.polyfil.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //PolyFils from MDN.
  2. (function() {
  3. if (!Array.prototype.map){
  4. Array.prototype.map = function(fun /*, thisArg */){
  5. "use strict";
  6. if (this === void 0 || this === null || typeof fun !== "function"){
  7. throw new TypeError();
  8. }
  9. var
  10. t = Object(this),
  11. len = t.length >>> 0,
  12. res = new Array(len),
  13. thisArg = arguments.length >= 2 ? arguments[1] : void 0;
  14. for (var i = 0; i < len; i++){
  15. if (i in t) {
  16. res[i] = fun.call(thisArg, t[i], i, t);
  17. }
  18. }
  19. return res;
  20. };
  21. }
  22. if (!Array.prototype.forEach){
  23. Array.prototype.forEach = function(fun /*, thisArg */){
  24. "use strict";
  25. if (this === void 0 || this === null || typeof fun !== "function"){
  26. throw new TypeError();
  27. }
  28. var
  29. t = Object(this),
  30. len = t.length >>> 0,
  31. thisArg = arguments.length >= 2 ? arguments[1] : void 0;
  32. for (var i = 0; i < len; i++){
  33. if (i in t){
  34. fun.call(thisArg, t[i], i, t);
  35. }
  36. }
  37. };
  38. }
  39. })();