ES6 Class type (simple understanding of encapsulation and inheritance)

        class People{
            constructor({name}){
                this.name = name;
            }
            say(){
                return "hello";
            }
        }

        const people = new People({name:"tom"});
        console.log(people);   // People {name:"tom"}
        console.log(people.say())  //hello

        // inherited 
        class the extends People {Jack    // Jack inherited People 
            constructor (Options) {
                super (Options)    // before calling the super class inherits the parent method to give 
                the this .age = options.age;
            }
        }

        const jack = new Jack({age:18,name:"jack"})
        console.log(jack)   //Jack {age:18,name:"jack"}
        console.log(jack.say())  //hello

 

Guess you like

Origin www.cnblogs.com/webmc/p/11944926.html