typeScript中的class用js如何实现

ts版本:

class Animal{

    fullStr:string;

    constructor(public color,public size,public age){

        this.fullStr=color+' '+size+' '+age

    }

}

let cat=new Animal("red","1KG","2")


js版本

let Animal =( function(){

            function Animal(color,size,age){

                this.color=color;

                this.size=size;

                this.age=age;

                this.fullStr=color+' '+size+' '+age;

            }

             return Animal;

}())

let cat=new Animal("red","1KG","2")

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,452评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,959评论 0 23
  • 此刻是寒假的第十八天,一天大概也就是起床吃饭再躺下,每日三餐缩减到了两餐甚至一餐。 从睁眼看到隔着窗帘透来...
    娜子Nazi阅读 417评论 0 0
  • 姐单位有个卫生纸杀手,每次去厕所,生怕纸带的不够,好家伙,突突突的扯上超级长的一大坨,目测比裹脚布都长,都快能把她...
    丛铭阅读 704评论 2 5