2. Let's talk about JavaScript
JavaScript is becoming a platform
X compiles to JavaScript, X = almost anything
Trend: asm.js, WebAssembly... not designed to be written by human
4. Why
Learn once, Write everywhere
Better tooling compares to JavaScript: gofmt, gooracle, gorename...
Easy concurrency: channels and goroutines instead of callback.
5. GopherJS
compiles Go into JavaScript
sourcemap
compatibility is really good. support channels and goroutines
can compile itself!
GopherJS Playground(http://gopherjs.github.io/playground/)
Example: https://github.com/shurcooL/Go-Package-Store(https://github.com/shurcooL/Go-Package-Store)
14. Import Carefully
No dead code elimiation yet
hello world with fmt
//753kb
import"fmt"
funcmain(){
fmt.Println("helloworld")
}
hello world with JS API
//64kb
import"github.com/gopherjs/gopherjs/js"
funcmain(){
js.Global.Get("console").Call("log","helloworld")
}
15. Blocking
Callbacks should never be blocking
//thiswillproduceanerror
js.Global.Get("myButton").Call("addEventListener","click",func(){
someBlockingFunction()
})
Wrap it into a goroutine to fix it
//thisworks!
js.Global.Get("myButton").Call("addEventListener","click",func(){
gofunc(){
someBlockingFunction()
}()
})
17. Good Architecture
OP = Custom Byte Code
Design as whatever you like
{"op":"move","target":"player","params":{"x":100,"y":100}}
<xml><enterprise><op>move</op><target>player</target></enterprise></xml>
Text-based protocol: Cross-platform, Easy to debug, Easy to parse