From 1e707dcd2bd9748ef5d81d7db884fb71e3014694 Mon Sep 17 00:00:00 2001 From: Olmo Maldonado Date: Sun, 29 Mar 2009 12:41:42 -0700 Subject: [PATCH] Fixed a mistake in the Spec and fixed undefined returns in Array.item --- Source/Native/Array.js | 5 +++-- Specs/Native/Array.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Native/Array.js b/Source/Native/Array.js index 53057942..e671ca55 100644 --- a/Source/Native/Array.js +++ b/Source/Native/Array.js @@ -78,12 +78,13 @@ Array.implement({ }, item: function(at){ + if (!this.length) return null; if (at < 0) at += this.length; - return this[at]; + return (at < this.length) ? this[at] : null; }, getLast: function(){ - return this.item(-1); + return (this.length) ? this.item(-1) : null; }, getRandom: function(){ diff --git a/Specs/Native/Array.js b/Specs/Native/Array.js index c6f1d972..8b48b4a2 100644 --- a/Specs/Native/Array.js +++ b/Specs/Native/Array.js @@ -167,7 +167,7 @@ describe("Array Methods", { 'should return the item': function(){ var arr = [1,2,3,4]; value_of(arr.item(0)).should_be(1); - value_of(array.item(-1)).should_be(4); + value_of(arr.item(-1)).should_be(4); }, 'should retun null if no item or no items in the array': function(){ -- 2.11.4.GIT