# decorator

修饰器类

# bind

# bindMethod

在线运行API

绑定方法的作用域

  • 示例:
    点击查看代码示例




     












    import { bindMethod } from "@goodluck/util";
    class Test {
        private status = true;
    
        @bindMethod
        public trigger() {
            // 从外部调用时,因此处有bindMethod修饰器,无论何种情况,this一定是指向当前class Test的作用域
            if(!this.status) return;
            this.func();
        }
        private func() {
            console.log("func");
        }
    }
    const test = new Test();
    test.trigger();
    

# bindClass

绑定类中所有方法的作用域

  • 示例:
    点击查看代码示例


     















    import { bindClass } from "@goodluck/util";
    
    @bindClass
    class Test {
        private status = true;
    
        // 从外部调用时,因class Test有bindClass修饰器,无论何种情况,调用class Test中的任何方法,方法中this都一定指向class Test的作用域
        public trigger() {
            if(!this.status) return;
            this.func();
        }
        private func() {
            console.log("func");
        }
    }
    const test = new Test();
    test.trigger();