What is the difference between Window and window?

前端 未结 3 632
温柔的废话
温柔的废话 2020-11-30 07:17

What is Window ?

Here\'s what I see on the console in Chrome :

    window
    Window {top: Window, window: Window, location: Location,         


        
相关标签:
3条回答
  • 2020-11-30 07:28

    Window is a function, as you can see. It's the constructor for the windows (but you can't build new windows directly with the constructor, you usually use the Window.open function). Window.prototype thus holds the methods you can call on the window).

    window is the global variable holding an instance of Window, it represents the browser window containing your document (not really a "window" usually, rather a tab in modern browsers).

    You can check that

    window instanceof Window
    

    is

    true
    
    0 讨论(0)
  • 2020-11-30 07:35

    console outputs from the Chrome browser:

    console.log(window instanceof Window);      // true
    console.log(window.constructor === Window); // true
    console.log(this);   // Window {document:document, alert:ƒ, setTimeout:ƒ,..}
    console.log(window); // Window {document:document, alert:ƒ, setTimeout:ƒ,..}
    console.log(Window); // ƒ Window() { [native code] }
    
    0 讨论(0)
  • 2020-11-30 07:37

    Window is the constructor function that is used to create window.

    To see this, try alert(window.constructor === Window).

    0 讨论(0)
提交回复
热议问题