Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactions avec Javascript should use globalThis instead of window #2524

Open
denis-migdal opened this issue Dec 6, 2024 · 2 comments
Open

Comments

@denis-migdal
Copy link
Contributor

In the documentation : https://brython.info/static_doc/3.13/fr/jsobjects.html

Examples should use globalThis instead of window :

from browser import globalThis

Indeed, globalThis is the standard way to access global values, working in window and non-window context, cf https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis

Brython does remove browser.window in Node and WebWorker contexts.

@denis-migdal
Copy link
Contributor Author

denis-migdal commented Dec 6, 2024

Note: browser.globalThis doesn't seem to be supported by Brython, but browser.self is.

I think self is standard in window environment and Webworker, but might not be in other environment (even if they seem to implement it).

So at least, examples should use from browser import self to access JS global variables, but ideally globalThis.

@denis-migdal
Copy link
Contributor Author

Also : self would be confusing inside methods where we use self like the JS this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant