Improve compliance with Array methods in ES5 when passed a null value. (ES5 Array methods treat null like [])

This commit is contained in:
Ryan W Tenney
2010-12-06 23:30:43 -05:00
parent e63f44f798
commit cdcf18b79c
3 changed files with 47 additions and 5 deletions

View File

@@ -83,6 +83,7 @@ $(document).ready(function() {
equals(_.indexOf(numbers, 2), 1, 'can compute indexOf, even without the native function');
var result = (function(){ return _.indexOf(arguments, 2); })(1, 2, 3);
equals(result, 1, 'works on an arguments object');
equals(_.indexOf(null, 2), -1, 'handles nulls properly');
});
test("arrays: lastIndexOf", function() {
@@ -92,6 +93,7 @@ $(document).ready(function() {
equals(_.lastIndexOf(numbers, 0), 8, 'lastIndexOf the other element');
var result = (function(){ return _.lastIndexOf(arguments, 1); })(1, 0, 1, 0, 0, 1, 0, 0, 0);
equals(result, 5, 'works on an arguments object');
equals(_.indexOf(null, 2), -1, 'handles nulls properly');
});
test("arrays: range", function() {