今天要来介绍TypeScript(TS)的类别(Class),
以下几项是需要特别注意的。
属性(Property)
建构函式(Constructor)
函式(Function)
类别的宣告如下,
class 类别名称 {
//类别程序码
}
类别范例如下,
class Employee {
//属性(Property)
empId: number;
empName: string;
//建构函式(Constructor)
constructor(id: number, name: string) {
this.empId = id;
this.empName = name;
}
//函式(Function)
showInfo() {
return this.empId + "-" + this.empName;
};
}
其中,类别中可以包含属性(Property)、建构函式(Constructor)及函式(Function),
使用方式如下,
let emp1 = new Employee(1, "Mary");
console.log(emp1.empId) ; //1
console.log(emp1.empName) ; //Mary
console.log(emp1.showInfo()) ; //1-Mary
可由上述方式带入与取出资料。
今天介绍类别的使用方式,
有写过C#的人肯定会觉得很熟悉,
写法相当类似,
因此对於写过C#的人来说学习起来也是相较容易的喔。
<<: 【Day11】Git 版本控制 - git clone & git pull
>>: Angular ng-container 与 ng-template
适用於身分识别的 Microsoft Defender 是利用内部部署 Active Directo...
1.命名方式不可以用 10_XX _XXX 英文开头 2.bootstrap是利用他人的css 套用...
今天继续针对 Data Analytics Pipeline on AWS 中常见的 AWS 服务来...
在C# 中包含所谓的 「保留关键宇」 ,就是C# 本身的指令名称, 不能用来宣告变数、常数、类别及方...
领导无关职称、职位或是流程图,而是一个生命影响了另一个生命。 Leadership is not a...