You can obfuscate it, but there's no way of protecting it completely.
example obfuscator: https://obfuscator.io
No, it's not possible. If it runs on the client browser, it must be downloaded by the client browser. It's pretty trivial to use Fiddler to inspect the HTTP session and get any downloaded js files.
Then again, obfuscation only prevents casual snooping, and doesnt prevent people from lifting and using your code.
You can try compiled action script in the form of a flash movie.
However, the main case in which I want to really 'hide stuff' is when I'm publishing an email address. Note, there is the problem of Chrome when you click on 'inspect element'. It will show your original code: every time. This is why obfuscation is generally regarded as being a better way to go.
On that note, I take a two pronged attack, purely to slow down spam bots. I Obfuscate/minify the js and then run it again through an encoder (again, this second step is completely pointless in chrome).
Maybe it's enough to slow down a few spam bots. I haven't had any spam come through using this (!yet).
One of the best compressors (not specifically an obfuscator) is the YUI Compressor.
The only way to partially hide it, at least from the less technical minds, is to obfuscate.
Obfuscation makes it harder for humans to read it, but not impossible for the technically savvy.
The only safe way to protect your code is not giving it away. With client deployment, there is no avoiding the client having access to the code.
So the short answer is: You can't do it
The longer answer is considering flash or Silverlight. Although I believe silverlight will gladly give away it's secrets with reflector running on the client.
I'm not sure if something simular exists with the flash platform.
©2020 All rights reserved.