Python or JavaScript? Although many friends are still arguing about who is stronger and who has a brighter future, there is no doubt that the competition has a clear answer in the Web front-end area. Based on the browser platform, if you abandon JavaScript, we have no choice of items.
Well, maybe the answer is not so absolute. JavaScript has become a target of choice for many other programming languages (examples include TypeScript, Emscripten, Cor, and Cheerp). Python has a large group of followers, and the existing powerful library resources make it an ideal alternative for JavaScript or translation.
Here are four projects that will smoothly bring Python into the JavaScript world:
Transcrypt
This is a newly-emerged Python-to-JS translator. Transcrypt has made an impressive commitment to the quality level of its generated code. First, it preserves as much of the original Python code structure as possible, including multiple inheritance and lambda expressions. The Python source code can also be invoked directly on objects within the namespace in JavaScript. If you try to access document.getElementById in Python, the converted code will also switch to using document.getElementById in JavaScript.
According to the description of the document, Transcrypt is using CPython's abstract syntax tree module to accomplish these translation tasks, which can be programmed to access according to Python's own code parsing method. Although the project is still in the Alpha beta phase, it has shown a surprisingly attractive appeal.
Jiphy
The so-called jiphy, which stands for "JavaScript in, Python out"-is the ability to convert both in two directions. In addition, code from two languages can be blended before being converted to another language.
Jiphy's current largest short board is that it supports only a subset of Python's feature sets. Class and default parameters are not yet supported, but adorners and exception mechanisms are already working. This is mainly because Jiphy insists on direct line-to-line translation between source and target code, but its developers are also beginning to look at new features in ES6, with the aim of incorporating more advanced Python functionality into the scope of support.
Brython
Perhaps one day, when the WebAssembly vision becomes a reality, we will be able to choose any language we prefer for WEB development. And Brython has its own understanding of this-or at least for Python 3--: Why wait?
Brython uses a set of JavaScript libraries to emulate all of the keywords in Python 3 and most of the built-in plug-ins, thus achieving the goal of using Python version 3 as a client-side WEB programming scenario. Scripts written by Python can be added directly to a Web page, while Brython also supports a set of Advanced Python module interfaces (browser) for performing collaboration with the DOM, which is typically done directly in JavaScript.
However, Brython also keeps the browser's limitations on JavaScript code--such as not supporting the processing of local file systems.
Rapydscript
Rapydscript promises to "make Python-style JavaScript code no worse." "The project is conceptually similar to Coffeescript: coding in Python, generating JavaScript code, and simultaneously playing the best of both worlds." In Python, it has clear grammatical rules; In JavaScript, it has anonymous functions, DOM operations, and the ability to use existing JavaScript libraries such as jQuery or the node. JS kernel.