[英]how to make an object an instanceof of its own prototype's property
taking a standard browser as example, 以标准浏览器为例,
there is the Window class instantiated as window variable 有实例化为window变量的Window类
window variable also contains the Window constructor (window.Window) window变量还包含Window构造函数(window.Window)
test this in your (standard) browser: 在您的(标准)浏览器中进行测试:
alert(window instanceof window.Window);
var asd = function(){};
asd.prototype.test = asd;
var x = new asd();
alert(x instanceof x.test);
now, window is also instanceof EventTarget that is stored in window.EventTarget 现在,window也是存储在window中的EventTarget的实例。
how to inherit EventTarget in the window object? 如何在窗口对象中继承EventTarget?
I'm answering to myself :| 我对自己说:|
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);
there is a better way to do this? 有更好的方法吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.