我有一个打字稿
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"自动"翻译成学生的财产?
感谢
答案 0 :(得分:1)
因为您在参数名称前写了public
,所以创建了一个参数属性。如果您不想要属性,可以在那里删除public
关键字。