// 1, the definition of class TS / * ES5: function the Person (name) { this.name = name; this.run = function () { the console.log (this.name) } } var P = the Person new new ( ' Zhang '); p.run () * / / * TS define classes: class {the Person name: String; // property front keyword is omitted public constructor (n: string) {// constructor class is instantiated the method of triggering when this.name n-=; } RUN (): void { Alert (this.name); } } var p = new Person ( 'John Doe'); p.run () * / / * class {the Person name: String; constructor (name: String) {// constructor class instance when the method of triggering this.name name =; } getName (): String { return this.name; } the setName (name: String): void { this.name = name; } } var P = the Person new new ( 'John Doe'); Alert (p.getName ()); p.setName ( 'John Doe'); Alert (p.getName ()); * / // 2, TS inheritance in the extends, Super // class the Person { // name: String; // constructor (name: String) { // this.name = name; // } // RUN (): String { // return this.name} {$ `` motion // } // } // / / var p = new Person ( 'Wangwu'); // // Alert (p.run ()) // class the extends the Web the Person { // constructor (name: String) { // Super (name); / * constructor initializes the parent class * / // } // } // var new new the Web W = ( 'John Doe'); // Alert (w.run ()); // method ts inherited parent class Discussion subclasses and methods consistent // class the Person { // name: String; // constructor (name: String) { // this.name = name; // } // RUN (): String { // return this.name} {$ `` motion // } // } // // new new var P = the Person ( 'Wangwu'); // // Alert (p.run ()) // class the extends the Web the Person { // constructor (name: String) { // Super (name ); / * initialize the parent class's constructor * / // } // RUN (): String { // return this.name} {$ `motion - subclass` // } // Work () { // alert ( `$ {this.name} working`) // } // } // var new new the Web W = ( 'John Doe'); // // Alert (w.run ()); // // w.work (); // Alert (w.run ()); // class 3 inside modifiers typescript which define the properties of time to give us three modifier / * public: the public in the current class inside, child class A, the outside can access protected: the type of protection which the current class, subclass which can be accessed from outside the class can not access the private: private access inside the current class, subclass, class method no external access attribute if not the default modifier is added to the public (public) * / // public: public class which, subclass, class outside can access // class the Person { // public name: String; / * public property * / // constructor ( name: string) { // this.name = name; // } // RUN (): String { // return this.name} {$ `motion` // } // } // // new new var P = the Person ( 'WANG five '); // // Alert (p.run ()) // class the extends the Web the Person { // constructor (name: String) { // Super (name); / * initialize the parent class's constructor * / / / } // RUN (): String { // return this.name} {$ `motion - subclass` // } // Work () { // alert ( `$ {this.name} working`) // } // } // var new new the Web W = ( 'John Doe'); // w.work (); // class public external access attribute // {the Person class // public name: String; / * public property * / // constructor (name: String) { // this.name = name; // } // RUN (): String { // return $ `{ motion this.name} ` // } // } // var P = the Person new new ( 'ha'); // Alert (p.name); // protected: protection class type which, subclass which can access, outside of the class can not access // {the Person class // protected name: String; / * public property * / // constructor (name: String) { // this.name = name; // } // RUN (): String { // return $ `{ motion this.name} ` // } // } // var P = the Person new new ( 'Wangwu'); // Alert (p.run ()) // class the extends the Web the Person { // constructor (name: String) { // Super (name); / * initialize the parent class's constructor * / // } // Work () { // alert ( `$ {this.name} working`) // } // } // var new new the Web W = ( 'John Doe. 11'); // w.work (); // Alert (w.run ( )); // outer protective outer class can not access attribute type // class the Person { // protected name: String; / * protection type * / // constructor (name: String) { // this.name = name; // } // RUN (): String { // return this.name} {$ `motion` // } // } // var P = the Person new new ( 'ha'); // Alert (P. name); //private: private class which can be accessed, subclass, class method no external access // class the Person { // Private name: String; / * private * / // constructor (name: String) { // this.name = name; // } // RUN (): String { // return this.name} {$ `motion` // } // } // class the extends the Web the Person { // constructor (name: String) { // Super (name) // } // work () { // the console.log ({$ `` working this.name}) // } // } {the Person class Private name: String; / * private * / constructor (name: String) { the this .name = name; } RUN (): String { return `$ { the this .name motion}` } } var P = new new Person ( 'ha' ); Alert (p.run ());