为什么在构造函数'this'DOMWindow

Why is DOMWindow not defined when the constructor of 'this' is DOMWindow

本文关键字:DOMWindow this 构造函数 为什么      更新时间:2023-09-26

我试图找到DOMWindow,但它一直说它是未定义的。我怎么得到它?

(function() {
    alert(this.constructor); // function DOMWindow() { [native code] }
    alert(DOMWindow); // DOMWindow is undefiend
})();

怎么了??

也许你想要的是alert(window)还是alert(window.constructor) ?DOMWindow是创建window的构造函数。

(function() {
    alert(this.constructor); // function DOMWindow() { [native code] }
    alert(window); 
    // or...
    alert(window.constructor);
})();
// window shows:
// [Object DOMWindow]
// window.constructor shows:
// function DOMWindow() { [native code] }