Skip to content
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

Wishlist: binding for: new Image #10

Open
udhos opened this issue Jun 8, 2015 · 2 comments
Open

Wishlist: binding for: new Image #10

udhos opened this issue Jun 8, 2015 · 2 comments

Comments

@udhos
Copy link

udhos commented Jun 8, 2015

Want constructor for javascript Image.

I am currently using this work-around:

func newImage() *js.Object {
    return js.Global.Call("eval", "(new Image())")
}

image := newImage()
image.Set("onload", func() {
    //go onLoad(gl, t, textureURL) // call onload handling goroutine
})
image.Set("src", textureURL)
@dmitshur
Copy link
Member

dmitshur commented Jun 9, 2015

This is also a valid feature request. This is WebGL-specific (and therefore less portable), unlike #11, but it is faster because image decoding happens in fast browser (C++) code rather than in compiled JavaScript (see relevant discussion here).

Note that you don't need to use eval in your current workaround, instead do this:

func newImage() *js.Object {
    return js.Global.Get("Image").New()
}

@udhos
Copy link
Author

udhos commented Jun 9, 2015

Thanks for the hint about js.Global.Get("Image").New() !

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