Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #2177 from ibolmo/fix-2169-array-filter-mutations

Fixes 2169.
  • Loading branch information...
commit 71cef509edef32427f97ba1f8231d75c5d8e0b64 2 parents bb22a20 + 676f6ce
@ibolmo ibolmo authored
Showing with 19 additions and 2 deletions.
  1. +3 −2 Source/Types/Array.js
  2. +16 −0 Specs/1.4base/Types/Array.js
View
5 Source/Types/Array.js
@@ -26,8 +26,9 @@ Array.implement({
filter: function(fn, bind){
var results = [];
- for (var i = 0, l = this.length >>> 0; i < l; i++){
- if ((i in this) && fn.call(bind, this[i], i, this)) results.push(this[i]);
+ for (var value, i = 0, l = this.length >>> 0; i < l; i++) if (i in this){
+ value = this[i];
+ if (fn.call(bind, value, i, this)) results.push(value);
}
return results;
},
View
16 Specs/1.4base/Types/Array.js
@@ -26,4 +26,20 @@ describe('Array', function(){
expect([].some.call(object, fn)).toBe(false);
});
+ describe('Array.filter', function(){
+
+ it('should return the original item, and not any mutations.', function(){
+
+ var result = [0, 1, 2].filter(function(num, i, array){
+ if (num == 1){
+ array[i] = 'mutation';
+ return true;
+ }
+ });
+
+ expect(result[0]).toEqual(1);
+ });
+
+ });
+
});
Please sign in to comment.
Something went wrong with that request. Please try again.