3

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)

4
  • "I got to a file named DHTML.js" — I can't see that in the repository for the project you are looking at Commented Jul 21, 2017 at 9:53
  • Quentin, you are correct, It does not exist in this repository. I think It's related somehow to the pycharm, but I just don't know. I will add this info to the question Commented Jul 21, 2017 at 9:56
  • "I ran into a JS code I want to use and I don't understand some parts of it. I use the pycharm environment to edit it." — PyCharm is an IDE designed for editing Python. It isn't optimised for dealing with JavaScript. Commented Jul 21, 2017 at 9:58
  • I need to fuse this script with some python code, that's why pycharm. I added some more specific questions, do you know maybe the answers to them? Commented Jul 21, 2017 at 10:03

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

"The window object is supported by all browsers" … that support JavaScript.
"It represents the browser's window" — that barely scrapes the surface of what it represents.
"w3schools" — are not as bad as they once were, but are still awful. They are best avoided.
Wow, three comments and a downvote for just one thing?! And that's just because you don't like w3s?! There is an edit function for comments too! The information there might not be as good as it could be, but not wrong and easy to understand for newcommers. Added moz dev too as source and changed the text a bit. @Quentin
slither.io is a game, your posted repo is just a bot for this. The properties used there are available by this game and just use in the bot. That's the reason why they are magically there. @Yair
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.