4 ms·
Javascript, The Good Parts, is not really relevant to today's Javascript, unless it's been refreshed. I remember working through it 10+ years ago: * `var` is n
by pcthrowaway 3y ago
Javascript, The Good Parts, is not really relevant to today's Javascript, unless it's been refreshed. I remember working through it 10+ years ago:
* `var` is no longer a thing.
* Even `let` is less common now.
* Using closures and prototypes to enable functions to be used like classes and have private variables and static variables, have been replaced with proper classes
Nowadays if you want to use the good parts of Javascript, just install eslint with insane defaults and let it tell you if you're trying to use the non-good parts
- andirk 3y agoIt's mostly outdated now, thank goodness, but anyone born after 1990 should read it cover to cover to appreciate the current state of JS and why we got here. hasOwnProperty?? Lol Looking at the book now, I still like some sections like "Curry" and "Memoization".
- tdba 3y ago>just install eslint with insane defaults where do I find these insane defaults?
- pcthrowaway 3y agolol, that was a typo, should have said "the sane defaults" On the other hand, it's a testament to the comment being written (or at least edited) by a human, and not an LLM right?
- von_lohengramm 3y agoThere used to be a lot of nice default packages, but I'm not aware of any actively maintained ones (other than "company X's config"). So instead... First, find the docs for ESLint and each of the integration packages that you've installed for each major dependency. Then just set each rule to the strictest setting. Then as you're developing, you'll start running into overzealous rules, prompting you to either disable the rule or write some override/exception. TSConfig, on the other hand, isn't extensible so you can just throw a couple configs from github.com/tsconfig/bases in your `"extends": [...]`. The base config `@tsconfig/strictest` might be of interest to you.
- capableweb 3y agoSurprise surprise, class syntax is basically just syntactic sugar on top of prototypes, and they essentially work the same way, besides bring able to have private members (which seems like a anti-pattern anyways). You'll able to accomplish exactly the same with both, so why create yet another way? Seems bit wasteful..
- pcthrowaway 3y agoYou could always create private members with closures.
- WorldMaker 3y agoThe syntax sugar paves a "garden path" for the common experience to be the best experience. It encodes "best practices" from previous prototype-based code, including private members. (They were always possible/always existed [as closures inside a constructor function, among even wilder solutions], but the patterns for building and using them was all over the map. It is nice to have standards now over a lot of ad hoc solutions.) I don't think it is wasteful, because it saves you from having to read books like "JS: The Good Parts" and hunt around for the right toolkit or design pattern to do the right things easily.
- leptons 3y agoSorry, but var is absolutely still a thing. It has plenty of valid use cases and sometimes using let just needlessly complicates the code.
- overgard 3y agoI'm curious, what use case? I can honestly say I don't think I've used var once in the last 5 years but maybe my coding style is different. Where is var useful?
- pcthrowaway 3y agoI imagine the person above deals with legacy codebases or vanilla JS (with no SPA framework) on the front-end, because I haven't seen "var" in over 5 years outside of those contexts.
- miohtama 3y agoThe joke is about the size of the books in the photo, not about JavaScript features.