I'm trying to understand the difference between regular javascript functions and arrow function. I have implemented code on js bin to see the outcome.
The issue is, I have a normal function and an arrow function as methods inside an object. I'm calling them being in the window scope. The first function call is working fine as I have expected. But in the second one, I use the bind method to bind 'john' object to the arrow function. Altho I use bind, it always takes the scope of the window object. Why is that?
this.table = 'Window table';
this.room = 'Window room';
let john = {
room: 'johns room',
table : 'johns table',
cleanTable(){
console.log(`cleaning ${this.table}`);
},
cleanRoom : () =>{
console.log(`cleaning ${this.room}`);
}
}
john.cleanTable();
john.cleanRoom.bind(john)();
######### output ##########
"cleaning johns table"
"cleaning Window room"
I want both of them to log the same thing which is "cleaning johns table". How can I achieve that?