* 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)
| 18389 | * @return {boolean} |
| 18390 | */ |
| 18391 | function hasArrayNature(obj) { |
| 18392 | return( |
| 18393 | // not null/false |
| 18394 | !!obj && ( |
| 18395 | // arrays are objects, NodeLists are functions in Safari |
| 18396 | typeof obj == 'object' || typeof obj == 'function') && |
| 18397 | // quacks like an array |
| 18398 | 'length' in obj && |
| 18399 | // not window |
| 18400 | !('setInterval' in obj) && |
| 18401 | // no DOM node should be considered an array-like |
| 18402 | // a 'select' element has 'length' and 'item' properties on IE8 |
| 18403 | typeof obj.nodeType != 'number' && ( |
| 18404 | // a real array |
| 18405 | Array.isArray(obj) || |
| 18406 | // arguments |
| 18407 | 'callee' in obj || |
| 18408 | // HTMLCollection/NodeList |
| 18409 | 'item' in obj) |
| 18410 | ); |
| 18411 | } |
| 18412 | |
| 18413 | /** |
| 18414 | * Ensure that the argument is an array by wrapping it in an array if it is not. |
no outgoing calls
no test coverage detected
searching dependent graphs…