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
[question] How do scopes work? #1462
Comments
For 1. I suggest to read through this section from the V8 blog: https://v8.dev/docs/embed#handles-and-garbage-collection. TLDR: scopes are not JS scopes, but scopes for handles of V8 objects. For 2. you wrote the solution yourself - just wrap your code in curly braces and then you will create lexical JS scopes that will not leak variables between them. |
let script = format!("{{{script}}}"); I temporarilly went with this but it feels By the way, thank you so much for pointing me to that article, I didn't know it existed. Maybe it's a good idea for it to be somewhere in the docs? |
I don't really know a native API that allows you to create lexical scopes.
That sounds like a good idea. I think we could add it to docstrings for all scope types. PRs are welcome! |
I'm not sure how scopes work, I would expect this to work but I get the error
<unknown>:0: Uncaught SyntaxError: Identifier 'x' has already been declared
.I would expect that doing something in new scopes would be the equivalent of
which would work.
If I've misunderstood the purpose of scopes could you
After that I can submit a PR adjusting the documentation
The text was updated successfully, but these errors were encountered: