Add Object.isHash.

This commit is contained in:
Tobie Langel 2007-10-14 08:08:42 +00:00
parent d195111a9d
commit 96af1b7579
4 changed files with 13 additions and 1 deletions

View File

@ -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]

View File

@ -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";
},

View File

@ -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,

View File

@ -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')));