在angular2環境中寫了一個自定義的debounce函數,因為使用了服務中的本地變量,所以沒有使用閉包在傳入函數作為參數時,遇到了兩個問題如何給傳入函數加入參數如何將傳入函數的作用域綁定在聲明他的component中代碼如下debounceTime(fn, delay) {if (isUndefined(this.timeout)) {this.timeout = setTimeout(() => { fn(); }, delay); } else { clearTimeout(this.timeout); this.timeout = setTimeout(() => { fn(); }, delay); }} emitSubmitDate(event) { this.submit_data['search'] = event.value; this.globalFuncService.setInfoListSource(this.request_type, this.request_url, this.submit_data); this.globalFuncService.emitInfoListSource();}staffSearch(event) { this.globalFuncService.debounceTime(this.emitSubmitDate, 500);}希望將event作為參數傳入emitSubmit函數,然后再將帶有event的emitSubmit傳入debounce實際遇到的問題是this的變化導致各種undefined本人js不是很好。。。希望各位多多指教
angular2函數去抖的問題
呼啦一陣風
2018-11-22 18:15:54