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

Classes

A class is an extensible template that is used to create objects with member variables to hold the state of the object and member functions that deal with the behavior of the object.

JavaScript only supports function-based and prototype-based inheritance to build reusable components. ECMAScript 6 provides the syntactic sugar of using classes in supporting object-oriented programming. However, not all browsers understand ES6 and we need transpilers, such as TypeScript, that compile the code down to JavaScript and target ES5, which is compatible with all browsers and platforms:

class Customer { 
    name: string; 
    constructor(name: string) { 
        this.name = name; 
   } 
    logCustomer() { 
        console.log('customer name is ' + this.name; 
   } 
} 
  
var customer = new Customer("Rajesh Gunasundaram"); 

This Customer class has three members: a name property, a constructor, and a logCustomer method. The last statement outside the customer class creates an instance of the customer class using the new keyword.

主站蜘蛛池模板: 洛川县| 三都| 保山市| 平度市| 宜宾县| 九江市| 龙泉市| 周宁县| 漳浦县| 崇明县| 平安县| 凭祥市| 铜陵市| 天长市| 得荣县| 盐城市| 东乌珠穆沁旗| 运城市| 西林县| 昔阳县| 巴楚县| 凤凰县| 石林| 福清市| 阿克陶县| 吉安县| 金昌市| 青冈县| 防城港市| 新营市| 邹平县| 乡城县| 图木舒克市| 南昌县| 顺昌县| 时尚| 海林市| 灵璧县| 抚松县| 内丘县| 西畴县|