Angular 2 code
heroes => this.heroes = heroes;
please tell me what this line exactly mean to?
heroes => this.heroes = heroes;
Is a function that takes a parameter heroes and the body of the function is
this.heroes = heroes
which assigns the parameter to this.heroes.
The arrow function has an implicit return which means that the return value is the result of the body.
this.heroes = heroes
returns heroes
The main difference is that => instead of
function(heroes) { this.heroes = heroes; }
ensures that this. keeps pointing to the current class instance similar to
(function(heroes) { this.heroes = heroes; }).bind(this)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With