how to make an object an instanceof of its own prototype's property
taking a standard browser as example,
there is the Window class in开发者_C百科stantiated as window variable
window variable also contains the Window constructor (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
how to inherit EventTarget in the window object?
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?
精彩评论