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

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

问题描述

我设计了一个模式来使用它们的原型来创建和扩展 html 元素.这在非 ie 浏览器中就像一个魅力.示例代码可见@jsbin(见页面源码)

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)

这种模式的优势应该是速度(方法在元素原型链中,所以被引用一次).你猜对了:IE 不行.在 IE 中8 html 元素的原型是隐藏/不可访问的,因此对于您创建的每个元素,您必须再次引用非标准方法(如果您密集使用该模式,则会留下很多指针).我在网上搜索了解决方案,但只找到了复杂的解决方法.真的没有办法在 IE 中访问 HTML 元素原型吗?

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?

推荐答案

不,也不能保证您可以在 JavaScript 中处理 DOM 对象的原型.DOM 对象不是 ECMAScript 规范的一部分;在任何浏览器中,它们可能根本不是(从传统上讲也不是)原生 JavaScript 对象.

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.

此外,即使它们是原生 JS 对象,您也不能依赖t.el.constructor".‘constructor’ 不是标准属性,在 IE 中不可用,甚至在 Mozilla 中也不会执行您可能认为的操作.避免.

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天全站免登陆