javascript version from steve-brecher's evaluator