package jsruntime import ( "github.com/dop251/goja" "log" ) func (jr *JsRuntime) EnableTimeoutFunc() { jr.runtime.Set("setTimeout", func(call goja.FunctionCall) goja.Value { if fn, ok := goja.AssertFunction(call.Argument(0)); ok { //delay := call.Argument(1).ToInteger() var args []goja.Value if len(call.Arguments) > 2 { args = call.Arguments[2:] } // //time.Sleep(time.Duration(delay) * time.Millisecond) fn(nil, args...) } return jr.runtime.ToValue(123124512) }) jr.runtime.Set("clearTimeout", func(i int64) { log.Println("clearTimeout暂未支持") }) }