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

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.

主站蜘蛛池模板: 舒城县| 焦作市| 柳林县| 吉木萨尔县| 汤原县| 驻马店市| 醴陵市| 张家界市| 瑞昌市| 交口县| 鄂伦春自治旗| 六枝特区| 垫江县| 南乐县| 通州区| 汉川市| 镇雄县| 长白| 南平市| 东兰县| 阳曲县| 比如县| 运城市| 九江市| 南阳市| 德阳市| 巴彦县| 南岸区| 仁布县| 皮山县| 翼城县| 二连浩特市| 延吉市| 聂荣县| 平罗县| 朝阳区| 五寨县| 承德市| 白河县| 贺兰县| 防城港市|