I believe Coinhive mentioned above uses WebAssembly to do efficient mining in the browser. Webassembly is a relatively new technology which provides a way to execute compiled C++ code in the browser that runs much faster than Javascript.
So probably if you want to implement mining in a web browser WebAssembly is the way to go:
http://webassembly.org/