web: Better way to detect NodeJS

This commit is contained in:
Hajime Hoshi 2018-05-16 22:10:35 +09:00
parent c2df8326fc
commit a5eb1b84ab

View File

@ -18,12 +18,21 @@ package web
import (
"strings"
"sync"
"github.com/gopherjs/gopherjs/js"
)
var (
isNodeJSOnce sync.Once
isNodeJS = false
)
func IsNodeJS() bool {
return js.Global.Get("require") != js.Undefined
isNodeJSOnce.Do(func() {
isNodeJS = js.Global.Get("process") != js.Undefined
})
return isNodeJS
}
func IsBrowser() bool {