在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
interface Person { firstName: string, lastName: string } function greeter(person: Person) { return person.firstName + " " + person.lastName; } var user = {firstName: 'Jane', lastName: 'User'}; console.log(greeter(user));
class Student { fullName: string; // 构造函数参数中使用public是一种简写形式,它将自动创建具有该名称的属性 constructor(public firstName, public middleInitial, public lastName) { this.fullName = firstName + " " + middleInitial + " " + lastName; } } interface Person { firstName: string, lastName: string } function greeter(person:Person) { return person.firstName + " " + person.lastName; } var student = new Student('Jane', 'M', 'User'); console.log(greeter(student)); 生成的js代码:
chrome调试ts文件:
|
请发表评论