TS:ES6类的扩展
1. 公共、私有、受保护的修饰符
-
在typescript中,对ES6标准的类的成员做了扩展,即可以使用
public,private,protected,readonly
对成员进行修饰,限制其使用域。 -
理解protected与private的区别:
-
protected成员在其派生类(子类)中仍然可以访问到;
-
若将构造函数标记成protected,意味着这个类不能再包含他的类以外被实例化,但是能够被继承:
class Person { protected name : string; protected constructor(theName : string){ this.name = theName; } } // Employee 能够继承 Person class Employee extends Person { private department: string; constructor(name: string, department: string) { super(name); // 可以实现 this.department = department; } public getElevatorPitch() { return `Hello, my name is ${ this
-