4 ms·
I figure there’s 3 possibilities: I’m just dumb, I don’t use it enough, or JavaScript is poorly designed. For some reason, even after 20 years of using JavaScri
by user3939382 5y ago
I figure there’s 3 possibilities: I’m just dumb, I don’t use it enough, or JavaScript is poorly designed. For some reason, even after 20 years of using JavaScript on and off and reading a dozen books about it, I can’t articulate exactly how the language works, how scope is evaluated, the composition of objects and prototypes which has some kind of turtles-all-the-way-down thing going on with it. When I read explanations in books it’s like hmm ok.. I guess that makes sense. Then a week later I don’t remember. The languages I’ve spent the most time with are SQL, PHP, Bash, and Clojure, and I never felt that way about them. Maybe it’s just me.
- nicoburns 5y agoPrototypes are quite simple. An object may have a prototype. If it does then that prototype is just another object, which is considered the first objects parent (which works with method calls like class based inheritance). The chain ends because it's also possible for an object not to have a prototype.
- wruza 5y agoI also had this trouble, because for all other languages you can just tead the spec once and that’s it. But ES specs are too technical to be used as such. After few years I just read non-boring parts of ES6 and it cleared all dark corners. I’d say all of the articles on the internet are rehashing the spec in (at best) a dubious and ritualistic way, and have zero technical value if you ask me.
- bluepnume 5y agoMy advice is to start of with javascript by forgetting 100% about classes, inheritance, prototypes, and so on. Just use vanilla functions and objects, and when in need of something that looks like a class, reach for the revealing module pattern: https://gist.github.com/zcaceres/bb0eec99c02dda6aac0e041d0d4d7bf2 https://gist.github.com/zcaceres/bb0eec99c02dda6aac0e041d0d4...
- rustyminnow 5y agoI've used this pattern before, but run into issues when you want to write tests for "private" functions (like loadSong() in this example). What I've done is name them like _loadSong and expose them anyways, but that doesn't feel great. Is there a better way?
- moron4hire 5y agoYou don't write tests for private methods.
- exdsq 5y agoWhy not?
- shawnz 5y agoThe most obvious reason is that they're private and not normally reachable from your test code. But even conceptually there are problems with testing private methods. For example they likely expect to be called only while the class is in some specific state or in the middle of some atomic operation. Otherwise they could have just been made public.
- bmy78 5y agoBecause it’s assumed those private methods’ usage happens within public methods, which should be tested. By testing the public methods and all of its use cases you are also testing private ones. That way you can arbitrarily modify private methods without touching the tests (presuming you’re refactoring and don’t need to modify behavior).
- exdsq 5y agoThis seems to be building on rocky foundations though. It's unlikely a functions entire test vector gets checked during testing. This is a known risk (you can't test everything) but by leaving all the functions under a public function untested there is no safety net.
- orangecat 5y agoJavaScript is poorly designed. It was barely designed at all; Brendan Eich wrote it in ten days, and we would be better off if he had been a worse developer and hadn't been able to accomplish that. Instead Netscape shipped what should have been an internal 0.1, and got its deficiencies enshrined as documented features so they could never be fixed.
- BrendanEich 5y agoTen day Mocha had strict ==, so better in that regard. History is detailed at https://youtu.be/krB0enBeSiE https://youtu.be/krB0enBeSiE. Rather than assuming a too-simple version, check out the details for how things went down. Do-overs not possible, by better new forms over time helped. Honest q: Do you actually use modern JS at all?
- SPBS 5y agoFWIW the scoping in JavaScript is exactly the same in Go, so it's not something obscure that only JavaScript cooked up.