From 194fda0b6d8277491c7766f1df3aa32031f4bb9f Mon Sep 17 00:00:00 2001 From: Thomas Fuchs Date: Fri, 17 Aug 2007 11:06:07 +0000 Subject: [PATCH] =?UTF-8?q?prototype:=20Make=20sure=20Enumerable#include?= =?UTF-8?q?=20doesnt=20do=20type=20comparision.=20=20[Mislav=20Marohni?= =?UTF-8?q?=C4=87]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG | 2 ++ src/array.js | 2 +- src/enumerable.js | 4 ++-- test/unit/enumerable.html | 5 +++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 07bb563..c580428 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Make sure Enumerable#include doesn't do type comparision. [Mislav Marohnić] + * Add contextmenu to Event.DOMEvents. [Thomas Fuchs] *1.6.0_rc0* (August 15, 2007) diff --git a/src/array.js b/src/array.js index 89b6831..db192be 100644 --- a/src/array.js +++ b/src/array.js @@ -87,7 +87,7 @@ Object.extend(Array.prototype, { intersect: function(array) { return this.uniq().findAll(function(item) { - return array.include(item); + return array.detect(function(value) { return item === value }); }); }, diff --git a/src/enumerable.js b/src/enumerable.js index 2b2ae06..50d09d2 100644 --- a/src/enumerable.js +++ b/src/enumerable.js @@ -89,11 +89,11 @@ var Enumerable = { include: function(object) { if (Object.isFunction(this.indexOf)) - return this.indexOf(object) != -1; + if (this.indexOf(object) != -1) return true; var found = false; this.each(function(value) { - if (value === object) { + if (value == object) { found = true; throw $break; } diff --git a/test/unit/enumerable.html b/test/unit/enumerable.html index 064f247..982d40c 100644 --- a/test/unit/enumerable.html +++ b/test/unit/enumerable.html @@ -199,9 +199,10 @@ testInclude: function() {with(this) { assert(Fixtures.Nicknames.include('sam-')); assert(Fixtures.Nicknames.include('noradio')); - assert(Fixtures.Nicknames.include('htonl')); - assert(Fixtures.Nicknames.include('Ulysses')); assert(!Fixtures.Nicknames.include('gmosx')); + assert(Fixtures.Basic.include(2)); + assert(Fixtures.Basic.include('2')); + assert(!Fixtures.Basic.include('4')); }}, testInGroupsOf: function() { with(this) {