“Array.prototype.slice: 'this' is not a JavaScript object” error in IE8

前端 未结 3 1140
名媛妹妹
名媛妹妹 2021-01-12 01:59

It is my understanding that IE8 has access to the Array.prototype.slice method. Yet when I try to call it to turn a NodeList into an array, it give

3条回答
  •  失恋的感觉
    2021-01-12 02:49

    The error message is accurate - your nodelist is not a JavaScript object, it is a "Host Object", which you can't necessarily pass around like regular JavaScript objects. Run this code in IE8's JavaScript console:

    document.querySelectorAll("div") instanceof Object
    

    It returns false.

提交回复
热议问题