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

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.

主站蜘蛛池模板: 承德市| 平潭县| 顺平县| 金阳县| 兰坪| 米泉市| 普陀区| 宁波市| 夏津县| 营口市| 百色市| 汶川县| 仪陇县| 百色市| 上蔡县| 上饶县| 西乌珠穆沁旗| 陇西县| 夹江县| 常宁市| 大连市| 蒲江县| 晋江市| 兴海县| 酒泉市| 卢氏县| 通榆县| 绥江县| 永丰县| 赞皇县| 仪陇县| 娄烦县| 罗田县| 安塞县| 泰州市| 炉霍县| 长武县| 望都县| 东阳市| 永靖县| 晋州市|