JavaScript 到 Python 的翻译器和 JavaScript 解释器,完全使用纯 Python 编写 在线试用:
JavaScript 6 的支持是通过使用 Js2Py 将 JavaScript 库翻译实现的,该库位于 Babel. Babel 将 JS 6 翻译为 JS 5,然后 Js2Py 将 JS 5 翻译为 Python。唯一的缺点是翻译后的 babel.js 大约有 4 MB,导入如此长的 Python 文件大约需要 15 秒!
翻译 JavaScript 文件:
# this will translate example.js to example.py
>>> js2py.translate_file('example.js', 'example.py')
# example.py can be now imported and used!
>>> from example import example
>>> example.someFunction()
...ECMA 5.1 的每个特性都已实现(除了 'with' 语句):
>>> js2py.eval_js("Object.prototype.toString.call(Function('s', 'return s+arguments[1]')(new Date(), 7).__proto__)")
[obje
[](https://pepy.tech/project/js2py)
6
[{u'id': 1}, {u'id': 2}]
11暂无开放 Issues,或尚未同步最近议题。