[Golang] undefined Test in GopherJS
source link: http://siongui.github.io/2016/02/06/go-undefined-test-in-gopherjs/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
[Golang] undefined Test in GopherJS
February 06, 2016
Check if something (object, variable, API, ...) is undefined or not in GopherJS. Use js.Undefined in your if test.
For example, you can check if your browser supports localStorage API or not by:
package main import ( "fmt" "github.com/gopherjs/gopherjs/js" ) func main() { if js.Global.Get("localStorage") == js.Undefined { fmt.Println("Your browser does not support localStorage API") } else { fmt.Println("Your browser supports localStorage API") } }
Run Code on GopherJS Playground
For null test (if a variable is null), see [3].
References:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK