If you want, you can you can always use the Compile function and then use the llvm to asm.js compiler. I don't know anyone who has done this or how useful that would be.
You may also want to consider the EmbedCode function. https://reference.wolfram.com/language/ref/EmbedCode.html. That might be easier to use than APIFunction.