为什么参数在Typescript中被翻译成属性?

时间:2017-05-10 19:49:06

标签: typescript

我有一个打字稿

class Student {
    fullName: string;
    constructor(public firstName, public middleInitial, public lastName) {
        this.fullName = firstName + " " + middleInitial + " " + lastName;
    }
}

使用tsc我得到了

var Student = (function () {
    function Student(firstName, middleInitial, lastName) {
        this.firstName = firstName;
        this.middleInitial = middleInitial;
        this.lastName = lastName;
        this.fullName = firstName + " " + middleInitial + " " + lastName;
    }
    return Student;
}());

我想知道为什么参数firstName"自动"翻译成学生的财产?

感谢

1 个答案:

答案 0 :(得分:1)

因为您在参数名称前写了public,所以创建了一个参数属性。如果您不想要属性,可以在那里删除public关键字。