typescript Interface Extension

/*




typeScript Interface


    Interface Extension

   
*/


/*
Functions as an interface: the object-oriented programming, interfaces are defined in a specification that defines the behaviors and motions of the specification, in which the programming interface functions as a restriction and specifications. Interface defines a number of classes required to comply with the specification, the interface does not care about the internal state of these classes of data, do not care about the implementation details of these class methods, only the provisions of these class must provide some method, provided these methods the class will meet actual needs. The interface is similar to typescrip java, but also increased the more flexible interface types, including properties, functions, and the like can be indexed.

The definition of standards.

*/


// indexable interfaces: an array of object constraints (not used)



    // TS define an array of fashion 
        / *
            var arr: number [] = [2342,235325]


            var arr1:Array<string>=['111','222']
        */



        // can be bound to the array index of the interface 
                // interface UserArr { 
                @      [index: Number]: String 
                // }


                // // var arr: UserArr =, [ ', aaa',, ', bbb',];

                // // console.log(arr[0]);



                // var ARR: UserArr = [123, 'BBB']; / * error * /

                // console.log(arr[0]);


        // indexable constraint interface objects




                // interface UserObj{

                //     [index:string]:string
                // }


                // var ARR: UserObj = {name: 'John Doe'};






// Interface Extension: Interfaces can be inherited interfaces   


    // interface Animal{

    //     eat():void;
    // }

    // interface Person extends Animal{

    //     work():void;
    // }

    // class Web implements Person{

    //     public name:string;
    //     constructor(name:string){
    //         this.name=name;
    //     }

    //     eat(){

    //          the console.log (this.name + 'like to eat bread') 
    //      } 
    //      Work () {

    //          the console.log (this.name + 'write code'); 
    //      }
        
    // }

    // var new new the Web W = ( 'Li');

    // w.eat();











    
    interface Animal{

        eat():void;
    }

    interface Person extends Animal{

        work():void;
    }


    class Programmer{

        public name:string;
        constructor(name:string){
            this.name=name;
        }
        
        coding(code:string){

            console.log(this.name+code)
        }
    }


    class Web extends Programmer implements Person{
        
        constructor(name:string){
           super(name)
        }
        eat(){

            console.log ( the this .name + 'like to eat bread' )
        }
        work(){

            the console.log ( the this .name + 'write code' );
        }
        
    }

    var W = new new the Web ( 'Li' );

    // w.eat (); 

    w.coding ( 'ts write code');

 

Guess you like

Origin www.cnblogs.com/loaderman/p/11040423.html