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

Is there a way to not pollute global namespace? #877

Open
CreatCodeBuild opened this Issue Nov 2, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@CreatCodeBuild

CreatCodeBuild commented Nov 2, 2018

Is it possible to not compile code into global but to an object the user can supply?

I am imagining something like

// xxx.js
// Instead of doing
(function() { // ... GopherJS Code })(this)
// Do
(function() { // ... GopherJS Code })(myObject)

So that the importer/user can do

import myObject from "xxx"
@dmitshur

This comment has been minimized.

Member

dmitshur commented Nov 4, 2018

How much global namespace pollution is there? The generated JavaScript code is contained in a closure, and this parameter is needed for js.Global to access the right thing.

You can do things like js.Global.Set("foo", ...) to export something from Go code to other JavaScript code, which is described at https://github.com/gopherjs/gopherjs#providing-library-functions-for-use-in-other-javascript-code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment