How does a mining pool coordinate with different Javascript clients? I've been reading a little about those web sites taht surreptitiously had Javascript running on the page that is mining cryptocurrency.  How do those pieces of JS work code generally?  Specifically


Do all pieces of Javascript code report back to a central server which maintains a mining pool?
Does each piece of code get a separate piece of work to do (and get assigned a different worker ID) so the malicious web site can mine faster?
The web site doing this don't need to be considered malicious, the visitor could willing agree to do the mining in order to help it. Said that,


Yes, they need to, to know the hash of the merkle tree of the block the pool is trying to mine. Otherwise they would have to download the blockchain in the browser themselves, and that would take hours or days. They also should somehow receive transactions to include in their blocks. Javascript running on a webpage can't typically comunicate with a cryptocurrency node directly, only via http requests to the same page domain. 
Yes, they also need to, otherwise they would be wasting CPU time doing the same work. For example, visitor A could receive instructions to compute hashes for a block X with nounces ranging from 0 to 15999, visitor B with nounces from 16000 to 31999 and so on.