I am checking the arrow function introduced in ES6. If I have this piece of code with the function "addNinja":
addNinja=(ninja)=>{
ninja.id=Math.random();
let ninjas=[...this.state.ninjas,ninja];
this.setState({
ninjas:ninjas
})
console.log(this.state);
}
Is there any way that this can be written without the arrow function?
If I taking into account that these 2 are the same...
x=>x*2
function(x){
return x*2;
}
I will assume that I could rewrite the addNinja function like the code below but I get an error.
addNinja=function(ninja){
ninja.id=Math.random();
let ninjas=[...this.state.ninjas,ninja];
this.setState({
ninjas:ninjas
})
console.log(this.state);
}