Closed jeffreyeaton76 closed 8 years ago
@jeffreyeaton76 I'm going to guess this is because when you use deck.compare
in an event handler this
changes. Inside an event callback, this
becomes the element on which the event was fired. So if I have:
document.getElementById("button").addEventListener("click", deck.compare);
...this
would be the button.
That was totally it! Thanks!
I tried to call a method on an object (
deck.compare
) using an event handler. I expected it would work just as well as calling the method directlydeck.compare();
. When using the event handler it claims parts of my object method are undefined and this doesn't make sense to me. My repo link is https://github.com/jeffreyeaton76/war and my question is about lines 47 and 48; they are both commented out but when un-commented 47 works and line 48 creates the error.