Added JavaScript example code to README + Moved w.close() inside callback of the last w.publish

* Added JavaScript example code to README
* Moved w.close() inside callback of the last w.publish