Created
April 29, 2009 17:23
-
-
Save steida/103907 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Type.extend({ | |
/* | |
* BOM/DOM iterable objects are: array, arguments, nodeList | |
* - from bigger picture, iterable javascript objects has to support length and [] -> index access | |
* - but index access can't be tested.. :-( | |
* - also, for safari typeof nodeList == function.. | |
* - and length property has also string or function, which are uniterable | |
* - so duck typing ftw! | |
*/ | |
isIterable: function(item) { | |
return !!(item && (item.item || item.callee || item.__type == 'array')); | |
} | |
}); | |
"Type.isIterable": function() { | |
QWE()(function() { | |
value_of(Type.isIterable(arguments)).should_be(true); | |
value_of(Type.isIterable([])).should_be(true); | |
value_of(Type.isIterable(document.childNodes)).should_be(true); | |
value_of(Type.isIterable(null)).should_be(false); | |
value_of(Type.isIterable('qwe')).should_be(false); | |
value_of(Type.isIterable(undefined)).should_be(false); | |
value_of(Type.isIterable(true)).should_be(false); | |
value_of(Type.isIterable({})).should_be(false); | |
value_of(Type.isIterable(function() { })).should_be(false); | |
value_of(Type.isIterable(45)).should_be(false); | |
value_of(Type.isIterable(new Date())).should_be(false); | |
value_of(Type.isIterable(/df/)).should_be(false); | |
}); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment