instanceof operator fails when passing an object through windows

别等时光非礼了梦想. 提交于 2019-11-30 22:36:00

Since your window's Object and the source window's Object aren't the same thing, an instance of one won't be an instance of the other. You can use Object.prototype.toString to distinguish between objects and arrays:

if(Object.prototype.toString.call(m) === '[object Array]') {
    // It's an array
} else {
    // It's not
}

You can also use Array.isArray, if available.

Here's a demo. (It uses an <iframe> instead of a popup, by the way.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!