Frage

taking a standard browser as example,

there is the Window class instantiated 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?

War es hilfreich?

Lösung

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?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top