Reading class-based code in JavaScript makes me want to weep. class AbstractBaseWhatever { someMethod() { throw new Error('Not implemented'); } } C'mon, man... do better!
-
Show this thread
-
Meanwhile... class TheChildClass extends AbstractBase { someMethod() { this.somethingElse(); } } Uh, wait ... where is this.somethingElse() defined?! Who knows! Time to hunt through the prototype chain!
12 replies 7 retweets 79 likesShow this thread -
Replying to @mjackson
How'd this any different from: const someFunction() { somethingElse()? } And you need polymorphism, you need to pass functions around which makes looking them up harder than instance methods.
1 reply 0 retweets 4 likes -
Replying to @justinfagnani
I can go directly to the definition of somethingElse in this case. I know exactly where it is. It's night and day.
1 reply 0 retweets 1 like -
Replying to @mjackson
There could be plenty of indirection in the definition of somethingElse(): somethingElse = a.third.thing.bind(foo); Instance members are pretty trivial to look up. I do it every day.
1 reply 0 retweets 4 likes -
Replying to @justinfagnani
What I mean by "indirection" is "how easy is it to open a file and find where somethingElse is defined?" In the case of instance methods, it's not obvious. In the case of regular functions, it is.
2 replies 0 retweets 1 like -
Replying to @mjackson
I don't think it's as universally obvious as you state. You can get a function into a scope in any number of ways.
1 reply 0 retweets 0 likes -
Replying to @justinfagnani
Using JavaScript modules, the only way you can get a regular function (not a prototype method or a global or eval) in scope is through import. That's it.
3 replies 0 retweets 0 likes
The only way you can get something onto `this` is if it's defined in the base or super class. There's actually more places for a local binding to be defined.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 