角2订阅使用绑定
问题描述:
使用箭头功能VS命名函数变量当订阅到http观察对象最教程使用箭头功能:角2订阅使用绑定
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}
看起来有点混乱,但使用它越多,就越舒服。你会喜欢它,不想使用this.extractData.bind(this)
'this.function.bind(this)'_cleanner_?我不同意。 – Cerbrus
是的,它涉及到+10行的嵌入箭头函数 – user2080105