如何使一个对象成为它自己的原型属性的实例

how to make an object an instanceof of its own prototype's property

本文关键字:原型 属性 实例 自己的 它自己 何使 一个对象      更新时间:2023-09-26

以标准浏览器为例,

有一个实例化为窗口变量的Window类

window变量还包含window构造函数(window. window)

在你的(标准)浏览器中测试一下:

alert(window instanceof window.Window);
var asd = function(){};
asd.prototype.test = asd;
var x = new asd();
alert(x instanceof x.test);

现在,window也是存储在window中的instanceof EventTarget。EventTarget

如何在窗口对象中继承EventTarget ?

我在对自己说:|

var EvtTarg = function(){};
EvtTarg.prototype.justATest = function(){alert("asd");};
var Win = function(){};
Win.prototype = Object.create(EvtTarg.prototype);
Win.prototype.EvtTarg = EvtTarg;
Win.prototype.Win = Win;
var win = new Win();
alert(win instanceof win.Win);
alert(win instanceof win.EvtTarg);

有更好的方法吗?