:- use_module(library(strings)). :- js_script({|string|| function myfunc(a) ... |}).
The implementation uses =:/2, calling the JavaScript function eval().