Javascript Angular 2使用箭头函数订阅与使用bind命名函数变量订阅
订阅Http可观察对象时,大多数教程使用箭头函数:Javascript Angular 2使用箭头函数订阅与使用bind命名函数变量订阅,javascript,angular,typescript,Javascript,Angular,Typescript,订阅Http可观察对象时,大多数教程使用箭头函数: this.myService.getItems.subscribe( (data) => // do something, (errors) => //handle errors); 为什么不使用函数变量来生成更清晰的代码: this.myService.getItems.subscribe(this.extractData.bind(this), this.handleErrors.bind(this)); 这取决于你的风格。
this.myService.getItems.subscribe(
(data) => // do something,
(errors) => //handle errors);
为什么不使用函数变量来生成更清晰的代码:
this.myService.getItems.subscribe(this.extractData.bind(this), this.handleErrors.bind(this));
这取决于你的风格。第一次使用data=>{do something}看起来有点混乱,但使用得越多,就越舒服。您会喜欢它并且不想使用此.extractData.bindthisthis.function.bindthis是否更干净?我不同意。是的,当涉及到+10行的嵌入式箭头函数时