有没有办法在Internet Explorer中更改对象的原型? [英] Is there a way to change the prototype of an object in Internet Explorer?

查看:44
本文介绍了有没有办法在Internet Explorer中更改对象的原型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IE中,您不能使用 obj .__ proto__ = some_proto ,但是您可以通过使用函数继承来解决此缺陷,例如:

In IE you can't use obj.__proto__ = some_proto, but you can go around this deficit by using inheritance through function, e.g.:

func = function(){}
func.prototype = proto
obj = new func

此环岛的问题是丢失了对 obj 的旧引用,并且不会指向以 proto 为原型的新 obj .无论如何,有没有要改变IE中现有对象的原型?

The problem with this roundabout is that old references to obj are lost and won't point to the new obj with proto as prototype. Is there anyway to change the prototype of existing objects in IE?

推荐答案

不,没有.

__ proto __ 只是一个hack,您无论如何都不要使用它(这不是标准功能).当前,在JS中无法更改现有对象的原型.

__proto__ is just a hack and you should never use it anyway (it's not a standard feature). It is currently not possible in JS to change the prototype of an existing object.

相关问题/解答:更改通过文字初始化创建的对象的原型 查看全文

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