Arrow Functions (Gosinta)
var solarsystem = {
planets: ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter',
'Saturn', 'Uranus', 'Neptune', 'Pluto (?)'],
showPlanets: function() {
this.planets.forEach(function(planet, idx) {
console.log(this.planets[idx]);
})
}
};
solarsystem.showPlanets(); // crash! ⛔
var solarsystem = {
planets: ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter',
'Saturn', 'Uranus', 'Neptune', 'Pluto (?)'],
showPlanets: function() {
this.planets.forEach((planet, idx) => {
console.log(this.planets[idx]);
})
}
};
solarsystem.showPlanets(); // success! 🌍