Created
October 21, 2018 11:57
-
-
Save ufocoder/ea352b1cee49f77ca189ce57c3dda2bf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Метод #1: свойство constructor | |
| // Ненадежный метод | |
| function isArray(value) { | |
| return typeof value == 'object' && value.constructor === Array; | |
| } | |
| // Метод #2: instanceof | |
| // Ненадежный метод в связи с возможностью изменения прототипа объекта | |
| // Непредвиденные результаты при работе с `iframe` | |
| function isArray(value) { | |
| return value instanceof Array; | |
| } | |
| // Метод #3: Object.prototype.toString() | |
| // Улучшенная проверка плюс очень похода на функцию ES6 Array.isArray() | |
| function isArray(value) { | |
| return Object.prototype.toString.call(value) === '[object Array]'; | |
| } | |
| // Метод #4: ES6 Array.isArray() | |
| function isArray(value) { | |
| return Array.isArray(value); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment