This is a card in Dave's Virtual Box of Cards.

The Tale of this and the JavaScript developer

Created: 2023-12-18
a this sits on a developer's head and back, menacingly

A this reference wants to cross an event callback but cannot do it without being used in the function body, so it asks a JavaScript developer to use it. The developer hesitates, afraid this might contain the wrong reference when they get to the other side, but this promises not to, pointing out that it would crash along with the rest of the program if it contained the wrong reference. The JavaScript developer considers this argument sensible and agrees to use this in the function body.

Midway through the event, this contains the wrong reference and the program crashes, dooming them both and the user as well. The dying developer asks this why it contained the wrong reference despite knowing the consequence, to which this replies: "I am sorry, but I couldn’t resist the urge. It’s in the spec."


Adapted from the Wikipedia synopsis of The Scorpion and the Frog

https://en.wikipedia.org/wiki/The_Scorpion_and_the_Frog

Back to javascript.