Home twitter


046

A Review of this and Object Prototypes

June 17, 2020

I had an a-ha moment regarding the Discord authentication library I'm working on. I decided to revisit it, along with reopen 'this & Object Prototypes,' to work through alongside the code. There are four libraries I'm working to refactor and condense into one that's streamlined to serve one specific purpose, and much of the code is unruly and poorly documented. As such, I was struggling to understand why one library even existed. It presented one sparse function that was supposed to serve as a 'class' of sorts, and also serve as a sort of glue to bridge two other libraries. Super messy. Over and above that, one library hasn't been touched in over 6 years.

Yeah, I'm not about to rely on that one.

Anyway, the libraries are all written in this ES5 class-inheritance emulation style code that's just ... it's fuckin' messy as fuck. So I'm going through and rewriting much of it, changing what I recognize as a pseudo class into an object literal wherever I can do so, as it makes sense to me. But that one library with that single sparse function?

Man, that had me stumped for a good long minute.

I figured it out, though. Let's call this library with the single sparse function 'Library B.' B for Bridge. Simple enough for illustrative purposes. Now, after sitting with this bullshit for that good long minute, and having the text of 'Object Prototypes' to guide me, something finally clicked, and I began to understand the flow of information. So, one library gets called, we'll call it 'Library C,'and when its primary 'class' function is instantiated, it stuffs Library B full of a bunch of shit. THEN it copies all of that shit into the pseudo-class that Library C instantiated, followed by a bunch of code to further stuff the new pseudo-class with more methods. This happens after the first library, let's call it 'Library A,' instantiates its own pseudo-class that stuffs Library B with a bunch of shit and ALSO copies it all back into itself once it's done. Are you confused yet? Because holy fuck, I STILL am.

From the top: Library A calls Library B, stuffs it full of shit, copies it back to itself, stuffs itself full of more shit, and in the process, calls Library C. Library C then stuffs Library B with even more shit, copies ALL of that back into itself, and adds even more shit to itself.

And somewhere in there it does what it's supposed to do.

Okay, listen, I'm grateful for the exercise in problem solving. But if some of these authors took their time to actually learn how to work with JS instead of trying to force it to conform to their idea of programming, this shit would not be this messy. But they don't, and so here we are.

That's fine. This just means there's more of an opportunity for me to set myself apart.