* 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 `arguments
(obj)
| 17801 | * @return {boolean} |
| 17802 | */ |
| 17803 | function hasArrayNature(obj) { |
| 17804 | return( |
| 17805 | // not null/false |
| 17806 | !!obj && ( |
| 17807 | // arrays are objects, NodeLists are functions in Safari |
| 17808 | typeof obj == 'object' || typeof obj == 'function') && |
| 17809 | // quacks like an array |
| 17810 | 'length' in obj && |
| 17811 | // not window |
| 17812 | !('setInterval' in obj) && |
| 17813 | // no DOM node should be considered an array-like |
| 17814 | // a 'select' element has 'length' and 'item' properties on IE8 |
| 17815 | typeof obj.nodeType != 'number' && ( |
| 17816 | // a real array |
| 17817 | Array.isArray(obj) || |
| 17818 | // arguments |
| 17819 | 'callee' in obj || |
| 17820 | // HTMLCollection/NodeList |
| 17821 | 'item' in obj) |
| 17822 | ); |
| 17823 | } |
| 17824 | |
| 17825 | /** |
| 17826 | * Ensure that the argument is an array by wrapping it in an array if it is not. |
no outgoing calls
no test coverage detected