Skip to content
This repository was archived by the owner on May 28, 2020. It is now read-only.

Latest commit

 

History

History
65 lines (47 loc) · 866 Bytes

File metadata and controls

65 lines (47 loc) · 866 Bytes

decorators

  • Inject

    将指定的ng服务(包括自定义服务)注入到构造器中(Service、Controller、Filter等),同时绑定到this对象上,格式为 this._serviceName

     @Inject('$q')
     class Service {
     	getQ() {
     		return this._$q;
     	}
     }
  • Bind

    使用装饰器的方式实现Function.prototype.bind

     class Service {
     	
     	constructor(name) {
     		this.name = name;
     	}
     
     	@Bind
     	getName() {
     		return this.name;
     	}
     }
     
     const service = new Service('kuitos');
     const getName = service.getName;
     console.log(getName()); // kuitos
  • Debounce

    @Debounce(delay, context || this)

     class Service {
     	
     	@Debounce(100)
     	resize() {
     		
     		// debounce
     	}
     }
     
  • Throttle

    @Throttle(delay, context || this)

     class Service {
     	
     	@Throttle(100)
     	switchButton() {
     		// throttle
     	}
     }