Using typescript to develop JS code to improve code maintainability

Source: Internet
Author: User

function test () {     var gs = new Greeter (' SS ');    Alert (Gs.greet ());} Window.onload = Test;class Greeter {    greeting:string;    Constructor (message:string) {        this.greeting = message;    }    Greet () {        return "Hello," + this.greeting;    }}

Because JSON serialization interaction is often used in the background and foreground, it can be very handy if the background-defined model can be used in the foreground, and smart hints and type checking are also very good features.

In the duplicated component, modularity needs to be constantly changing today maintainability is important and useful

Let's look at the JS that it generates

function test () {    var gs = new Greeter (' SS ');    Alert (Gs.greet ());} Window.onload = Test;var Greeter = (function () {    //constructor function function    Greeter (message) {        this.greeting = message;    }    Greeter.prototype.greet = function () {        return "Hello," + this.greeting;    };    return Greeter;} ());//# Sourcemappingurl=file1.js.map

  

Type check variable check smart hints

Using typescript to develop JS code to improve code maintainability

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.