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

Better globals #490

Merged
merged 2 commits into from
Nov 8, 2024
Merged

Better globals #490

merged 2 commits into from
Nov 8, 2024

Conversation

kengorab
Copy link
Owner

@kengorab kengorab commented Nov 7, 2024

Top-level variables in a module are only hoisted to globals if they're referenced in a function (ie. captured). Since these variables can be referenced as globals from within those functions, there's no need to store them as captures for that function, and the function can effectively be invoked as if it were an ordinary function. Top-level variables that are not referenced in functions are treated effectively as locals within the module's wrapper function. Exported variables (which can only be top-level) are always hoisted to globals.

Top-level variables in a module are only hoisted to globals if they're
referenced in a function (ie. captured). Since these variables can be
referenced as globals from within those functions, there's no need to
store them as captures for that function, and the function can
effectively be invoked as if it were an ordinary function.
Top-level variables that are _not_ referenced in functions are treated
effectively as locals within the module's wrapper function.
Exported variables (which can only be top-level) are always hoisted to
globals.
@kengorab kengorab merged commit 904e681 into master Nov 8, 2024
1 check passed
@kengorab kengorab deleted the better-globals branch November 8, 2024 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant