Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a 'window' object in JavaScript? And what are its properties? [duplicate]

I ran into JavaScript code I want to use, and I don't understand some parts of it.

I use the PyCharm environment to edit it. The source of the code is the following: https://github.com/ErmiyaEskandary/Slither.io-bot

For example, in this part of the code:

var canvasUtil = window.canvasUtil = (function() {
return {
    // Ratio of screen size divided by canvas size.
    canvasRatio: {
        x: window.mc.width / window.ww,
        y: window.mc.height / window.hh
    },

    // Set direction of snake towards the virtual mouse coordinates
    setMouseCoordinates: function(point) {
        window.xm = point.x;
        window.ym = point.y;
    },

I don't understand what the "window" object is, and where it's defined. When I tried to find its definition, I got to a file named DHTML.js, where the only definition for window there was:

/**
@type {Window}
*/
Window.prototype.window = 0;

or

/**
@type {Window}
@const
*/
window = 0;

(This file is not a part of the repository.)

What is this window object? How does it work? And where can I find more information about it?

In the code - what does window.mc, for example, mean? I didn't found any information about the window's property. There are similar objects in the code like window, but this one appears the most.

(I tried to look it up but the information I found in W3Schools doesn't seems to be related: The Window Object)

like image 937
Yair Avatar asked Dec 04 '25 14:12

Yair


1 Answers

The JavaScript variable window is an object, representing a window containing a DOM document; the document property points to the DOM document loaded in that window. The window object is available in JavaScript of all browsers.

  • Window (MDN)
  • JavaScript Window - The Browser Object Model (W3Schools)
  • The Window Object (W3Schools)
like image 121
eisbehr Avatar answered Dec 07 '25 02:12

eisbehr