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

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.

主站蜘蛛池模板: 曲水县| 额敏县| 大城县| 平罗县| 峡江县| 徐闻县| 高雄市| 河曲县| 资溪县| 建阳市| 永城市| 北碚区| 嵩明县| 南投市| 贺兰县| 夏邑县| 平湖市| 塘沽区| 榆中县| 麻城市| 抚松县| 军事| 永德县| 竹北市| 上林县| 京山县| 赣州市| 灵寿县| 沅江市| 洛川县| 沙坪坝区| 长春市| 小金县| 阿鲁科尔沁旗| 津南区| 大竹县| 上栗县| 余江县| 旺苍县| 班戈县| 甘泉县|