The context can be your individual context (add a dict, add the page object, whatever). By adding the dot you are adding either the current page or whatever loop you are in (the context changes with with and range).
You can always use page itself to add the context of the current page (on list pages it’s the list page, not the page you might be ranging through). Or create your own dictionary:
{{ $context := dict "bla" "falsel" }}
{{- $exec := resources.ExecuteAsTemplate "foo.js" $context $script -}}
would result in foo.js having .bla set to “fasel”.
If you want to add the page context additionally:
{{ $context := dict "bla" "falsel" "page" . }}
Then .page would contain the page context, for instance .page.Title, etc.
Is that what you need?