Well, it can. V8 and other Javascript engines do Just-In-Time (JIT) binary compilation, meaning that they start by interpreting and executing each line of code as they read it, but when they see a function getting executed a lot, they convert just that function to native machine code as a performance optimization for the next time it gets called.
And, because this does happen, you can ship compiled Javascript--by dumping the memory-image of the Javascript interpreter after running it for a while (JITed routines and all) and then reloading it on the client end.
> meaning that they start by interpreting and executing each line of code as they read it, but when they see a function getting executed a lot, they convert just that function to native machine code as a performance optimization for the next time it gets called.
Technically V8 does not have an interpreter pass at all. It always JITs to machine code. It does have two compilers though: a fast JIT and a slow JIT. The fast one gets code running as quickly as possible so your app starts fast, but doesn't generate optimal code. The slow JIT kicks in for hot code and spends more timing compiling it to something that will run faster.
Well, it can. V8 and other Javascript engines do Just-In-Time (JIT) binary compilation, meaning that they start by interpreting and executing each line of code as they read it, but when they see a function getting executed a lot, they convert just that function to native machine code as a performance optimization for the next time it gets called.
And, because this does happen, you can ship compiled Javascript--by dumping the memory-image of the Javascript interpreter after running it for a while (JITed routines and all) and then reloading it on the client end.
node-webkit (an application framework similar to the one EA/Maxis uses for SimCity's UI) has a good example of this concept in action: https://github.com/rogerwang/node-webkit/wiki/Protect-JavaSc...