I want to make an event handler with setters and getters, but there is a problem. The this keyword is not working in my function inside the object correctly. I was looking everywhere, but I couldn't find the problem.
const Event = {
listen: ()=>{
console.log(this);
}
};
Event.listen();
This is a part of my code which returns me: Window {window: Window, self: Window, document: document, name: '', location: Location, …}
.
I tryed searching on google, documentation (mozzila), stackoverflow. I tryed deleting all parts of code to have only this object with this funciton.
I am excepting, that the this
will return the Event{listen:function}
object.
Thanks for your help.