箭頭函數(shù)表達式的語法比函數(shù)表達式更簡潔,并且沒有自己的this,arguments,super或new.target。箭頭函數(shù)表達式更適用于那些本來需要匿名函數(shù)的地方,并且它不能用作構造函數(shù)。
在hero.component中 我們定義了一個函數(shù)來獲取hero.service的請求
getHeroes(): void {
? ? this.heroService.getHeroes()
? ? .subscribe(heroes => this.heroes = heroes);
}
分解開等同于
getHeroes(): void { var _this = this; this.heroService.getHeroes() .subscribe(function(heroes) { _this.heroes = heroes; }); }
也可以寫成:
getHeroes(): void {
? ? this.heroService.getHeroes()
? ? .subscribe(newheroes => this.heroes = newheroes);
}
這種寫法,確實比JAVA 8 的Lambda 表達式和:: 寫法墨跡。。。文章來源:http://www.zghlxwxcb.cn/news/detail-530590.html
想簡化,但是又不夠徹底文章來源地址http://www.zghlxwxcb.cn/news/detail-530590.html
到了這里,關于解析 angular subscribe中, ES6 Arrow 箭頭函數(shù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!