真的没有办法在IE(< 8)中公开html元素的原型? [英] Is there really no way to expose the prototype of a html element in IE (<8)?

查看:96
本文介绍了真的没有办法在IE(< 8)中公开html元素的原型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用他们的原型制作了一个模式来创建和扩展html元素。这样就像在非浏览器中的魅力一样。示例代码可以在 jsbin 找到(参见页面源代码)



这种模式的优点应该是速度(方法在元素原型链中,所以它们被引用一次)。你猜对了:IE不去在IE< 8 html元素的原型是隐藏/不可访问的,所以对于您创建的每个元素,您必须再次引用非标准方法(如果您集中使用该模式,则留下很多指针)。我已经在网上搜索过解决方案,但只找到了复杂的解决方法。是否真的无法在IE中访问HTML元素原型?

解决方案

不,也不是它保证您可以通过JavaScript来处理DOM对象的原型。 DOM对象不是ECMAScript规范的一部分;在任何浏览器中,它们可能不是(并且传统上不是)本机JavaScript对象。



这就是为什么框架往往拥有自己的容器包装类。



即使它们是本机JS对象,您也不能依赖于't.el.constructor'。 构造函数不是标准属性,在IE中不可用,甚至在Mozilla中也不会执行您认为的功能。避免。


I cooked up a pattern to create and extend html elements using their prototype. This works like a charm in non-ie browsers. Example code can be found @jsbin (see page source)

The advantage of this pattern should be speed (the methods are in the elements prototype chain, so they are referenced once). You guessed right: IE no go. In IE < 8 the prototype of html elements is hidden/not accessible, so for every element you create, you have to reference the non standard methods again (leaving you with a lot of pointers if you use the pattern intensively). I have searched the web for solutions, but only found complex workarounds. Is there really no way to access a HTML elements prototype in IE?

解决方案

No, nor is it guaranteed you can fiddle with DOM objects' prototypes in JavaScript in general. The DOM objects are not part of the ECMAScript spec; they may not be (and traditionally speaking aren't) native JavaScript Objects at all, in any browser.

This is why frameworks tend to have their own ‘container’ wrapper classes.

Also you cannot rely on ‘t.el.constructor’ even if they were native JS Objects. ‘constructor’ is not a standard property, isn't available in IE, and even in Mozilla doesn't do what you might think it does. Avoid.

这篇关于真的没有办法在IE(&lt; 8)中公开html元素的原型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆