Implemented JavaScript version
Merge pull request #9 from rvagg/jsify

Rewrite in JavaScript