Skip to content

Commit

Permalink
Add Array#reduce shim for IE8
Browse files Browse the repository at this point in the history
  • Loading branch information
ixti committed Aug 1, 2012
1 parent 1f64fb0 commit eeabb3a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
14 changes: 14 additions & 0 deletions demo/js/js-yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ if (!Array.prototype.map) {
};
}

if (!Array.prototype.reduce) {
Array.prototype.reduce = function (iterator, memo) {
if (undefined === memo) {
memo = this[0];
}

this.forEach(function (val, key) {
memo = iterator(memo, val);
});

return memo;
};
}

if (!Function.prototype.bind) {
Function.prototype.bind = function bind(context) {
var func = this;
Expand Down
14 changes: 14 additions & 0 deletions js-yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ if (!Array.prototype.map) {
};
}

if (!Array.prototype.reduce) {
Array.prototype.reduce = function (iterator, memo) {
if (undefined === memo) {
memo = this[0];
}

this.forEach(function (val, key) {
memo = iterator(memo, val);
});

return memo;
};
}

if (!Function.prototype.bind) {
Function.prototype.bind = function bind(context) {
var func = this;
Expand Down
6 changes: 3 additions & 3 deletions js-yaml.min.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions support/browserify/30_extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ if (!Array.prototype.map) {
};
}

if (!Array.prototype.reduce) {
Array.prototype.reduce = function (iterator, memo) {
if (undefined === memo) {
memo = this[0];
}

this.forEach(function (val, key) {
memo = iterator(memo, val);
});

return memo;
};
}

if (!Function.prototype.bind) {
Function.prototype.bind = function bind(context) {
var func = this;
Expand Down

0 comments on commit eeabb3a

Please sign in to comment.