- Expert Angular
- Mathieu Nayrolles Rajesh Gunasundaram Sridhar Rao
- 81字
- 2021-07-15 17:05:34
Generic classes
Similar to generic interfaces, we can also define generic classes. We define classes with a generic type in angle brackets (<>) as follows:
class GenericClass<T> { add: (a: T, b: T) => T; }
var myGenericClass = new GenericClass<number>(); myGenericClass.add = function(a, b) { return a + b; };
Here, the generic class is instantiated by passing the generic data type as number. So, the add function will process and add two variables of type number passed as parameters.
推薦閱讀
- HTML5移動(dòng)Web開(kāi)發(fā)技術(shù)
- TypeScript入門(mén)與實(shí)戰(zhàn)
- 測(cè)試驅(qū)動(dòng)開(kāi)發(fā):入門(mén)、實(shí)戰(zhàn)與進(jìn)階
- GeoServer Cookbook
- Mastering Adobe Captivate 2017(Fourth Edition)
- Building a Home Security System with Raspberry Pi
- 三維圖形化C++趣味編程
- 實(shí)用防銹油配方與制備200例
- Learning Bayesian Models with R
- 信息安全技術(shù)
- 正則表達(dá)式經(jīng)典實(shí)例(第2版)
- Python數(shù)據(jù)結(jié)構(gòu)與算法(視頻教學(xué)版)
- Active Directory with PowerShell
- 青少年學(xué)Python(第2冊(cè))
- Python計(jì)算機(jī)視覺(jué)與深度學(xué)習(xí)實(shí)戰(zhàn)