Compiling to JavaScript: an alternative solution for incompatibility

Source: Internet
Author: User

JavaScript has been used for Web development more or less. Although Javascript is everywhere, it is still hard to be liked. Javascript performance was not optimal until VMS like Google V8, Apple/WebKit Nitro/SquirrelFish Extreme, and Firefox TraceMonkey appeared.The implementation of incompatibility between multiple browsers also makes development very painful.. JQuery and other class libraries provide convenient and easy-to-use abstractions. They can be programmed using the same API, or even eliminate incompatibility.

Another solution: compile as JavaScript

Another way to solve this problem is to completely hide Javascript and use it as the compilation target. Google's GWT is a very mature example. It accepts Java code written in a subset of Java APIs and compiles it into Javascript For browsers. In reality, one of the real cases of GWT is the Google Wave client. Recently, implementations of some other languages also include this row column.

Avi Bryant, author of The Smalltalk Seaside Web framework, developed Clamato, A Smalltalk dialect that can be compiled into common Javascript. Avi described the design principles of Clamato in his interview with InfoQ ureruby.

The Clamato guide page allows you to open a ClamatoSmalltalk class browser in your browser to view and edit the Clamato source code. To search for a class, use the text box in the upper-left corner of the class browser. What is interesting is that the self-hosted PEG-based Clamato parser typed "PP" in the text box to see the parser and classes of various combinations ). From the HTMLCanvas class in the Clamato browser of the Seaside-style HTML constructor, we can see the shadow of Seaside. A visualization component can be used to construct a GUI. For example, the counter component in the Guide:

 
 
  1. renderOn: html  
  2.   html h3 with: @counter.  
  3.   html button  
  4.     with: '+';  
  5.     onClick: [@counter := @counter + 1. self reload].  
  6.   html button  
  7.     with: '-';  
  8.     onClick: [@counter := @counter - 1. self reload]. 

The rendeon: html line defines a new method. The other part of the example is the method body, which constructs the HTML with a header and two buttons, and the two buttons are configured with the event processor. Coincidentally, another browser-based Smalltalk-GWT Smalltalk has recently emerged. Peter Fisk, its author, previously created Vista Smalltalk, which can be Based on. Net or ActionScript. GWT Smalltalk uses GWT to generate Jaavscript running in the browser.

GWT Smalltalk is just in its infancy, but it has developed rapidly. XMPP is currently supported, which makes it easy to interact with Google Wave. XMPP is an extremely important part of Google Wave ). You can get more details from the Industry Misinterpretations interview dashboard Peter Fisk and the GWT Smalltalk blog.

After talking about Smalltalk, let's take a look at Python. It also has its own Javascript compiler-pyjamas:

Pyjamas is an independent Python-to-Javascript compiler, an AJAX framework/class library, and a Widget set API. The best place to get started is online pyjamas books.

The other language that can be compiled into Javascript is Moby Scheme. It is so striking that it is aimed at mobile devices which are currently Android)-compiling code into Javascript. This approach is feasible because there is PhoneGap, And the WebKit-based browser in Android comes with an efficient Javascript VM. PhoneGap is a class library that allows Javascript to access the functions of a local device. The device can be an accelerometer, GPS, camera, or address book. PhoneGap authors use it to build bridges between devices that communicate with different smart phones. They can have different programming environments, as long as WebKit and quick Javascript VMS are available. By allowing Javascript to access device functions, you can develop cross-platform applications for smart phones.

  1. IBM's new EGL tool: more powerful JavaScript?
  2. 10 most commonly used JavaScript udfs
  3. New Features of JavaScript 2.0 come closer to the classic Language
  4. Ranking of open-source languages: PHP and JavaScript are favored
  5. Uncover the most expensive line of Javascript code in history

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.