r/javascript • u/Waltex • Dec 05 '25
The missing standard library for multithreading in JavaScript
https://github.com/W4G1/multithreading
146
Upvotes
r/javascript • u/Waltex • Dec 05 '25
View all comments
Show parent comment
3
u/Waltex Dec 06 '25 edited Dec 06 '25
It is possible to get the code of a function as a string using Function.toString(). The short version is that this stringified code is then send to the WebWorker where it's "imported" as a data url (similar to
eval). We do not track which variables are in or outside the scope of the closure. It definitely is possible, but we do not want to ship the whole typescript compiler to the browser. This is why the library doesn't allow references from outside the closure. Everything you want available inside, has to be either imported inside usingawait import(...)or passed throughmove(...). Ideally in the future we want to have a compile time error when we accidentally reference something from outside the scope of the function.