misc/wasm: Possible bug in _makeFuncWrapper #36585
Labels
arch-wasm
WebAssembly issues
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, judging by the contents of the
master
branch.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Related to #36561, I came across another unexpected error
from the TypeScript compiler.
this
should usually be avoided in anonymous functions, due to its often unexpected behavior. It's possible that this is intended, but I wanted to point it out for two reasons:As a quick reminder about the behavior of
this
inside anonymous functions:this
defaults to the global scope (e.g.window
). In strict mode it defaults toundefined
.this
by usingbind
. In order to do this, you need a reference to the function. So if we have a function calledmyFunc
, you could call it this way:myFunc.bind(myObj).call()
. This would result inthis
being set tomyObj
.It was difficult for me to find where the function was called, but if you are not calling it via
bind
, it means thatthis
is alwaysundefined
. This might be a bug that should be addressed. On the other hand if everything still works,this
could simply be removed:If you are using
bind
, I would suggest simply passing in an argument to the function in order to adhere to JavaScript best practices. I'm not sure what the argument should be called since I don't have the full context of how this function is being used, but it would look something like this:Maybe there is some reason the function can't be written that way? I'm not sure.
What did you expect to see?
Again, I don't expect this file to compile without making changes since it wasn't written with TypeScript in mind. I was surprised by this particular error and I think it points to a potential bug.
What did you see instead?
The TypeScript compiler complains about the usage of
this
inside an anonymous function.The text was updated successfully, but these errors were encountered: