使用typescript開發js代碼提升代碼維護性

來源:互聯網
上載者:User

標籤:ring   png   img   esc   test   string   序列化   前台   pes   

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;    }}

  由於後台與前台經常用到json序列化互動 所以如果後台定義的model能夠拿到前台來使用將會非常方便 並且智能提示和類型檢查也是非常好的功能

在複製的組件話,模組化 需要不斷變化的今天 維護性很重要 更有用武之地

我們看看它產生的js

function test() {    var gs = new Greeter(‘ss‘);    alert(gs.greet());}window.onload = test;var Greeter = (function () {    //建構函式    function Greeter(message) {        this.greeting = message;    }    Greeter.prototype.greet = function () {        return "Hello, " + this.greeting;    };    return Greeter;}());//# sourceMappingURL=file1.js.map

  

類型檢查 變數檢查 智能提示

使用typescript開發js代碼提升代碼維護性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.