robertkrimen / otto

A JavaScript interpreter in Go (golang)

Home Page:http://godoc.org/github.com/robertkrimen/otto

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'document' is not defined

zhangxuanru opened this issue · comments

commented

otto := Otto.New()
otto.Set("require", require)
otto.Run(require("js/echarts.js"); require("js/1.js"); )

1.js:
console.log(document)

func require(call Otto.FunctionCall) Otto.Value {
file := call.Argument(0).String()
fmt.Printf("requiring: %s\n", file)
data, err := ioutil.ReadFile(file)
if err != nil {
fmt.Println(err)
panic(err)
}
_, err = call.Otto.Run(string(data))
//fmt.Println(string(data))
if err != nil {
fmt.Println(err)
panic(err)
}
return Otto.TrueValue()
}

'document' is not defined。 How to deal with this mistake?

commented

document is not part of ES5. That's an implementation-specific thing.