Skip to content

Officially supported things that get externalized to "null". #400

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

Open
dmitshur opened this issue Feb 14, 2016 · 2 comments
Open

Officially supported things that get externalized to "null". #400

dmitshur opened this issue Feb 14, 2016 · 2 comments

Comments

@dmitshur
Copy link
Member

This is a documentation issue/question.

From https://godoc.org/github.com/gopherjs/gopherjs/js, the only mention of things that get externalized to "null" is:

A nil pointer to Object is equal to JavaScript's "null".

$ goexec -quiet -compiler=gopherjs 'js.Global.Get("console").Call("log", (*js.Object)(nil))'
null

However, an (interface{})(nil) also gets externalized to a JavaScript null as far as I can tell:

$ goexec -quiet -compiler=gopherjs 'js.Global.Get("console").Call("log", (interface{})(nil))'
null

Also, in #145 (comment), @dominikh said:

Passing an untyped nil should work, as that gets translated to null.

I'm unsure how to achieve an untyped nil or if it's the same as a nil of type interface{}.

But in either case, I wanted to ask/confirm. Is the fact that (interface{})(nil) gets externalized to a JavaScript null an officially supported feature of GopherJS (that I can/should rely on)?

If so, is it a natural property of Go, or is it a special behavior that should be documented somewhere (since it's currently undocumented as far as I can see)?

@dmitshur
Copy link
Member Author

Friendly ping @neelance.

Somewhat related is #617 (/cc @myitcv). That issue is about internalization (JS -> Go), this is a question about externalization (Go -> JS).

@nevkontakte
Copy link
Member

To me this behavior seems fairly reasonable. So I guess we only need to update documentation to declare this behavior as intended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants