The best you can do is to define your own obscure language, call it #
Then write two compilers, #
to JavaScript (this one needs to be in JavaScript) & JavaScript to #
Then just have a single file on the client that gets some source written in #
from the server and then compile / evaluate it line by line on the fly.
Of course #
needs to be obscure, and the JavaScript -> #
compiler is so that you can just write your code in JavaScript and pre compile it to #
and store it on the server.
It's not secure. People can read the compiler and figure out what the JavaScript equivalent is, but if you can find me a single person who cares enough to do that and I'll be impressed.
A minor side effect is that your seriously damaging performance on the client side merely due to an obsession with hiding your source code.
[Edit]
Of course we obscure the compiler with minimizers and ensure that the compiler, compiles & runs internally without converting to easily readable javascript anywhere.