From 96af1b7579cdbc57b703ce6bc772123999b98a00 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Sun, 14 Oct 2007 08:08:42 +0000 Subject: [PATCH] Add Object.isHash. --- CHANGELOG | 2 ++ src/base.js | 4 ++++ src/hash.js | 2 +- test/unit/base.html | 6 ++++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index c9cd57b..3318851 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Add Object.isHash. [Tobie Langel] + * Performance improvements to String#times. [Martin Ström] * Make Ajax.Response#getHeaderJSON and Ajax.Response#getResponseJSON pseudo private instance methods. [Tobie Langel] diff --git a/src/base.js b/src/base.js index 82234e1..1ea0ba7 100644 --- a/src/base.js +++ b/src/base.js @@ -131,6 +131,10 @@ Object.extend(Object, { return object && object.constructor === Array; }, + isHash: function(object) { + return object instanceof Hash; + }, + isFunction: function(object) { return typeof object == "function"; }, diff --git a/src/hash.js b/src/hash.js index 0f31759..326cb0e 100644 --- a/src/hash.js +++ b/src/hash.js @@ -39,7 +39,7 @@ var Hash = Class.create(Enumerable, (function() { return { initialize: function(object) { - this._object = object instanceof Hash ? object.toObject() : Object.clone(object); + this._object = Object.isHash(object) ? object.toObject() : Object.clone(object); }, _each: each, diff --git a/test/unit/base.html b/test/unit/base.html index 650d070..2941793 100644 --- a/test/unit/base.html +++ b/test/unit/base.html @@ -298,6 +298,12 @@ assert(!Object.isArray({})); }}, + testObjectIsHash: function() { with(this) { + assert(Object.isHash($H())); + assert(Object.isHash(new Hash())); + assert(!Object.isHash({})); + }}, + testObjectIsElement: function() { with(this) { assert(Object.isElement(document.createElement('div'))); assert(Object.isElement(new Element('div')));