Skip to content

Feature request: js.Null #145

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

Closed
hajimehoshi opened this issue Jan 2, 2015 · 9 comments
Closed

Feature request: js.Null #145

hajimehoshi opened this issue Jan 2, 2015 · 9 comments

Comments

@hajimehoshi
Copy link
Member

IIUC, the initial value of js.Object and null in JavaScript are different. I found out that I need JavaScript null instead of nil when, for example, calling gl.bindFramebuffer whose second argument must be Framebuffer or null (not js.Object nil).

package main

import (
    "github.com/gopherjs/gopherjs/js"
)

func main() {
    var null1 js.Object
    print(null1) // Object {$key: function}
    var null2 = js.Global.Call("eval", "null")
    print(null2) // null
}

Now that there seems no easy way to get JavaScript null with GopherJS. can we have new API to get such null, or is there anything I missed?

@dmitshur
Copy link
Member

dmitshur commented Jan 2, 2015

for example, calling gl.bindFramebuffer whose second argument must be Framebuffer or null (not js.Object nil).

Have you tried it? What happens if you give it js.Object nil?

print(null2) // null

Note, you can use null2.IsNull() to test if it's the JS null.

@dominikh
Copy link
Member

dominikh commented Jan 2, 2015

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

@hajimehoshi
Copy link
Member Author

Thanks, but now github.com/gopherjs/webgl can't be compiled.

@dmitshur
Copy link
Member

dmitshur commented Jan 3, 2015

Thanks, but now github.com/gopherjs/webgl can't be compiled.

No problem, I'll fix it.

@dmitshur
Copy link
Member

dmitshur commented Jan 3, 2015

honnef.co/go/js/dom needs to be updated too. /cc @dominikh

@hajimehoshi
Copy link
Member Author

No problem, I'll fix it.

Great. Are you working on it now? If no, I'll fix this.

@dmitshur
Copy link
Member

dmitshur commented Jan 3, 2015

I am, but I can only make a PR, I don't have push rights for https://github.com/gopherjs/webgl. /cc @ajhager

Edit: Made gopherjs/webgl#8.

@dmitshur
Copy link
Member

dmitshur commented Jan 3, 2015

By the way, to update any package automatically (ala go fix), you can do:

gofmt -w -r 'x.IsNull() -> x == nil' *.go 
gofmt -w -r 'x.IsUndefined() -> x == js.Undefined' *.go

@neelance
Copy link
Member

neelance commented Jan 3, 2015

Merged gopherjs/webgl#8

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

4 participants