* Perform a heuristic test to determine if an object is "array-like". * * A monk asked Joshu, a Zen master, "Has a dog Buddha nature?" * Joshu replied: "Mu." * * This function determines if its argument has "array nature": it returns * true if the argument is an actual array, an `arg
(obj)
| 10697 | * @return {boolean} |
| 10698 | */ |
| 10699 | function hasArrayNature(obj) { |
| 10700 | return ( |
| 10701 | // not null/false |
| 10702 | !!obj && ( |
| 10703 | // arrays are objects, NodeLists are functions in Safari |
| 10704 | typeof obj == 'object' || typeof obj == 'function') && |
| 10705 | // quacks like an array |
| 10706 | 'length' in obj && |
| 10707 | // not window |
| 10708 | !('setInterval' in obj) && |
| 10709 | // no DOM node should be considered an array-like |
| 10710 | // a 'select' element has 'length' and 'item' properties on IE8 |
| 10711 | typeof obj.nodeType != 'number' && ( |
| 10712 | // a real array |
| 10713 | Array.isArray(obj) || |
| 10714 | // arguments |
| 10715 | 'callee' in obj || |
| 10716 | // HTMLCollection/NodeList |
| 10717 | 'item' in obj) |
| 10718 | ); |
| 10719 | } |
| 10720 | |
| 10721 | /** |
| 10722 | * Ensure that the argument is an array by wrapping it in an array if it is not. |
no outgoing calls
no test coverage detected