What is window.__context?

I know it’s usually better to get the answer to these questions with a google search, but I can’t seem to find it anywhere online. I wrote a function for creating a GlowScript canvas and adding it to an inputted div. I based it off of the code given on the website with some changes. Here is the function:

function make_box(my_div){
    window.__context = {glowscript_container: document.getElementById(my_div)}
    var scene = canvas();

    // create some shapes:

I think the first line is required to add the canvas to the div. Without the line, I get the error:

Uncaught TypeError: Cannot set property ‘canvas_selected’ of undefined

I don’t really understand what it’s doing however, and what the window context means. Does anyone have any insight into the line? Thanks!

People generally prefix variables with underscores to denote that they are ‘private’ variables or to make them harder to accidentally overwrite by other JS code, especially if you are going to add them to a global object like window. But there is nothing special about window.__context. I’m assuming the library you are using to create the canvas requires it to be set properly before it will function. That’s just the way the library decided to implement its functionality.

1 Like

Thank you. I also was a bit confused by the syntax, but I believe it’s defining an attribute of window to have the attribute glowscript_container with a value of the div.

One reason I wanted to understand it is to create different graphics in different divs which can communicate with one another. I was able to do it by simply writing that line multiple times with different divs. Here is the code on codepen. It is a slider in one div which controls the size of a box in another. (Style is added to one div to confirm they are in separate divs).

It seems like