var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); //修饰符:主要是描述类中成员(属性,构造函数,方法)的可访问性 //public 修饰符 类中成员默认的修饰符 代表的公共的任何位置都可以访问类当中的成员 //private 修饰符 类中成员如果使用这个修饰符 外部成员无法访问这个数据 子类也无法访问 //protected 修饰符 类中成员如果使用这个修饰符 外部无法访问数据 子类可以访问数据 (function () { //定义一个类 var Person = /** @class */ (function () { // public name: string // private name: string // protected name:string function Person(name) { this.name = name; } Person.prototype.eat = function () { console.log('我是eat方法', this.name); }; return Person; }()); //定义一个子类 var Student = /** @class */ (function (_super) { __extends(Student, _super); function Student(name) { return _super.call(this, name) || this; } Student.prototype.play = function () { console.log('我是play方法', this.name); }; return Student; }(Person)); var per = new Person('小红'); console.log(per.name); })();