官术网_书友最值得收藏!

  • 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.

主站蜘蛛池模板: 长阳| 石景山区| 遵化市| 松潘县| 桦甸市| 中江县| 庆安县| 阳东县| 沂南县| 海宁市| 田阳县| 阿图什市| 兴宁市| 凤山市| 嵊泗县| 万盛区| 临潭县| 安丘市| 敦煌市| 扶沟县| 区。| 奈曼旗| 龙胜| 武邑县| 漠河县| 闽侯县| 自治县| 江口县| 遵义市| 波密县| 乌兰察布市| 红原县| 西华县| 额济纳旗| 和林格尔县| 台南市| 沙雅县| 射阳县| 大理市| 寿宁县| 长海县|