Added JavaScript example code to README + Moved w.close() inside callbac...

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