oldie-polyfills.src.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * (c) 2010-2019 Torstein Honsi
  3. *
  4. * Simple polyfills for array functions in old IE browsers (6, 7 and 8) in
  5. * Highcharts v7+. These polyfills are sufficient for Highcharts to work, but
  6. * for fully compatible polyfills, see MDN.
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. /* eslint no-extend-native: 0 */
  11. 'use strict';
  12. if (!Array.prototype.forEach) {
  13. Array.prototype.forEach = function (fn, ctx) {
  14. var i = 0,
  15. len = this.length;
  16. for (; i < len; i++) {
  17. if (
  18. this[i] !== undefined && // added check
  19. fn.call(ctx, this[i], i, this) === false
  20. ) {
  21. return i;
  22. }
  23. }
  24. };
  25. }
  26. if (!Array.prototype.map) {
  27. Array.prototype.map = function (fn) {
  28. var results = [],
  29. i = 0,
  30. len = this.length;
  31. for (; i < len; i++) {
  32. results[i] = fn.call(this[i], this[i], i, this);
  33. }
  34. return results;
  35. };
  36. }
  37. if (!Array.prototype.indexOf) {
  38. Array.prototype.indexOf = function (member, fromIndex) {
  39. var arr = this, // #8874
  40. len,
  41. i = fromIndex || 0; // #8346
  42. if (arr) {
  43. len = arr.length;
  44. for (; i < len; i++) {
  45. if (arr[i] === member) {
  46. return i;
  47. }
  48. }
  49. }
  50. return -1;
  51. };
  52. }
  53. if (!Array.prototype.filter) {
  54. Array.prototype.filter = function (fn) {
  55. var ret = [],
  56. i = 0,
  57. length = this.length;
  58. for (; i < length; i++) {
  59. if (fn(this[i], i)) {
  60. ret.push(this[i]);
  61. }
  62. }
  63. return ret;
  64. };
  65. }
  66. if (!Array.prototype.some) {
  67. Array.prototype.some = function (fn, ctx) { // legacy
  68. var i = 0,
  69. len = this.length;
  70. for (; i < len; i++) {
  71. if (fn.call(ctx, this[i], i, this) === true) {
  72. return true;
  73. }
  74. }
  75. return false;
  76. };
  77. }
  78. if (!Array.prototype.reduce) {
  79. Array.prototype.reduce = function (func, initialValue) {
  80. var context = this,
  81. i = arguments.length > 1 ? 0 : 1,
  82. accumulator = arguments.length > 1 ? initialValue : this[0],
  83. len = this.length;
  84. for (; i < len; ++i) {
  85. accumulator = func.call(context, accumulator, this[i], i, this);
  86. }
  87. return accumulator;
  88. };
  89. }
  90. if (!Object.keys) {
  91. Object.keys = function (obj) {
  92. var result = [],
  93. hasOwnProperty = Object.prototype.hasOwnProperty,
  94. prop;
  95. for (prop in obj) {
  96. if (hasOwnProperty.call(obj, prop)) {
  97. result.push(prop);
  98. }
  99. }
  100. return result;
  101. };
  102. }