diff --git a/CHANGES b/CHANGES index f41add77..2a07013a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +1.2.2 + - Changed reduce to follow the letter of the spec with regard to having and + owning properties. + - Fixed a bug where RegExps pass as Functions in some engines in reduce. + 1.2.1 - Adding few fixes to make jshint happy. - Fix for issue #12, function expressions can cause scoping issues in IE. diff --git a/es5-shim.js b/es5-shim.js index 3b1b7d1b..187148be 100644 --- a/es5-shim.js +++ b/es5-shim.js @@ -248,7 +248,7 @@ if (!Array.prototype.some) { if (!Array.prototype.reduce) { Array.prototype.reduce = function reduce(fun /*, initial*/) { var len = +this.length; - if (typeof fun !== "function") + if (typeof fun !== "function" || fun instanceof RegExp) throw new TypeError(); // no value to return if no initial value and an empty array @@ -280,6 +280,7 @@ if (!Array.prototype.reduce) { }; } + // ES5 15.4.4.22 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight if (!Array.prototype.reduceRight) { @@ -329,7 +330,7 @@ if (!Array.prototype.indexOf) { if (i < 0) i += length; for (; i < length; i++) { - if (!owns(this, i)) + if (!(i in this)) continue; if (value === this[i]) return i; @@ -349,7 +350,7 @@ if (!Array.prototype.lastIndexOf) { i += length; i = Math.min(i, length - 1); for (; i >= 0; i--) { - if (!owns(this, i)) + if (!(i in this)) continue; if (value === this[i]) return i; diff --git a/package.json b/package.json index 9b856897..09c64c18 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "es5-shim", "description": "ES5 as implementable on previous engines", - "version": "1.2.1", + "version": "1.2.2", "homepage": "http://github.com/kriskowal/es5-shim/", "contributors": [ "Kris Kowal (http://github.com/kriskowal/)",