Decorator

            //装潢器实质是一个函数
            //装潢对象能够运用多个装潢器
            //装潢器能够带参数
            //装潢器润饰类,实例要领
            //aop 设想头脑(log,邮件发送)
        function school(target){
            target.schoolName="快手直播";
        }
        function hometown(diqu){
            return function(target){
                target.home=diqu;
            }
        }
        function studyke(kemu){
            return function(target){
                target.ke=kemu;
            }
        }
        
        @hometown("根里的")
        @school
        
        class Student {
            constructor(name){
                this.name=name;
            }
            @studyke("jquery")
            study(){
                console.log(this.name+"在看"+this.ke);
            }
        }
        console.log(Student.schoolName);//显现快手直播.
        console.log(Student.home);//显现根里的.
        
        let l = new Student("曹伟");
        l.study();//显现曹伟再看jquery.
        
        @school
        class Teacher {
            
        }
        console.log(Teacher.schoolName);//显现快手直播.
    原文作者:骚胖
    原文地址: https://segmentfault.com/a/1190000010283707
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞