-
Notifications
You must be signed in to change notification settings - Fork 18k
syscall/js: possibility of using String.prototype.* methods on strings #35917
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
Comments
Workaround: you can call JS String.prototype.toLowerCase.call("FOO") In Go: js.Global().Get("String").Get("prototype").Get("toLowerCase").Call("call", js.ValueOf("FOO")) I have used this in hexops/vecty#251 in order to workaround this problem. |
I think it should. The current API relies on fmt.Println(body.Get("nodeName").Call("toLowerCase"))
fmt.Println(body.Get("nodeName").Call("charAt", 3)) Not pasting the code here. But I can send a CL if Richard is okay with it. |
This is because of JavaScript's autoboxing.
gets interpreted as
I do not yet see why syscall/js should emulate autoboxing. Is there any proper use case? In my opinion, for the examples above the proper solution is to use the |
Thanks for the explanation.
I agree, I don't think that would be a good change.
It should also be possible to use JavaScript's It sounds like it is possible with one of these two ways: var str string = "FOO"
js.Global().Get("String").New(str).Call("toLowerCase")
// or
js.Global().Get("String").Get("prototype").Get("toLowerCase").Call("call", str) So nothing needs to be done. I'll close this if there aren't objections. |
It looks like there are no objections. ping @dmitshur. |
With GopherJS, it was possible to call the
String.prototype.toLowerCase
method on a JavaScriptString
:https://gopherjs.github.io/playground/#/ekZpm7tuW4
It's possible I'm overlooking something trivial, but this doesn't seem possible with
syscall/js
API of WebAssembly. Consider the same program modified to usesyscall/js
:Its output with Go 1.13.4 is:
Depending on whether a JavaScript
String
type is considered a "JavaScript object" or not, this may be consistent withjs.Value.Get
documentation, which says:I'm wondering if it's possible to use
toLowerCase
withsyscall/js
API? If not, should it be possible?/cc @neelance
The text was updated successfully, but these errors were encountered: