fix js issue that caused undefined behavior in some occasions
Merge pull request #23 from mistio/staging.js_fix

fix js issue that caused undefined behavior in some occasions