关于老版本ie不支持hasOwnProperty方法的解决

关于document、window、Element在浏览器的表现:

alert(typeof window); //chorme  Object     IE  Object
alert(typeof Element); //chorme function   IE Object
alert(typeof document); //chorme Object     IE Object

可以看到Element和window在IE中都是Object类型的。

老版本IE 的 DOM Element 是没有 hasOwnProperty 方法的。

还有 window 对象也没有 hasOwnProperty 方法。

可以考虑用 Object 对象的 hasOwnProperty 试试。

Object.prototype.hasOwnProperty.call(window, "property")
Object.prototype.hasOwnProperty.call(element, "property")

参考:https://segmentfault.com/q/1010000000260133

猜你喜欢

转载自blog.csdn.net/BingoXing/article/details/81938188