Web-browsers generally default to execute JavaScript in a Privately Scoped context…
eg.
<!-- the doit() function will be execute in a Private scoped context -->
<button onclick="doit()">Click me</button>
<!-- this function is defined in a Private scoped context, so it's not available outside that context -->
<script>
function somesuch() {
return "value";
}
</script>
When a Story Format’s engine starts up it processes the meta-data, like that representing the Passages and the Story JavaScript/Stylesheet areas of the project, that is embedded within the Story HTML file.
In the case of SugarCube the content of the Story JavaScript area is executed in a Private Scope context in a way that allows that context to have access to specific components of the engine.
eg. it basically passes references to those engine components as arguments to that Private context.
SugarCube does the same with any Private Scope context its engine creates to execute JavaScript, said practice is known as “being executed in a SugarCube context”. Which is why engine related components like setup and the APIs are available when doing things like the following…
<<set setup.thing to "value">>
<<link "Restart">>
<<run UI.restart()>>
<</link>>
…but those engine components are not available when you do something like…
<button onclick="UI.restart()">Restart</button>
When the web-browser, and thus the SugarCube engine, executes JavaScript it follows a set process for replacing (variable) references with their actually values…
eg. the setup reference in the following needs to be replace with the Generic Object value it represents, so that its thing property can be assigned a value.
<<set setup.thing to "value">>
If you have defined a custom “global-like” property on the web-browser’s window interface that has the same name…
window.setup = window.setup || {};
…then it is possible that the value of your setup Generic Object will be returned by the set process instead of that of SugarCube’s engine.