New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syscall/js: Add new convenient functions #44481
Comments
Any new API addition needs to be supported by requirements which will benefit a wide number of users using the package. Can you please outline your reasoning behind these new methods? When should the user call Invoke vs Invoke2? Go usually believes in one way of doing things, so diverging the API at this point does not seem to overshadow the benefit gained by introducing this new API. I believe the panic was deliberately written for a reason, but I cannot recall it at the moment. |
Let me explain: A primer for non-JS developers: In JS, the constructor ( Reasoning:
|
func errorwrap(v Value) (_ Value, rErr error) {
defer func() {
if e := recover(); e != nil {
err, ok := e.(*Error)
if !ok {
panic(e)
}
rErr = err
}
}()
return v, nil
}
func (v Value) New2(args ...interface{}) (Value, error) {
return errorwrap(v.New(args...))
}
func (v Value) Call2(name string, args ...interface{}) (Value, error) {
return errorwrap(v.Call(name, args...))
}
func (v Value) Invoke2(args ...interface{}) (Value, error) {
return errorwrap(v.Invoke(args...))
} |
Any progress on this issue? |
Add 3 new JS functions that are common and make them idiomatic Go in usage:
The text was updated successfully, but these errors were encountered: