3 ms·
It's like Python's itertools if: * list and dict were lacking vital methods like list.remove() and dict.__len__() * dicts weren't really a real thing (real on
by Macha 12y ago
It's like Python's itertools if:
* list and dict were lacking vital methods like list.remove() and dict.__len__()
* dicts weren't really a real thing (real ones coming in ES6 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... ), but it was easy to add random properties to arbitrary objects while accessing a missing one simply returned None, and so these were used instead
* Which leads to for x in dct being subtly broken in certain use cases unless you understand the above and how it interacts with prototypes
* So loads of utility functions were added to deal with the above facts, plus the kind of useful tools you would find in Python's functools and itertools and a large number of other utility functions while they're at it.
(EDIT: One of these days I will remember HN doesn't use Markdown, but not today)
- csense 11y agoSo basically the JS built-in container and prototype semantics are totally stupid, broken and confusing. I already knew this. Apparently underscore is a community-driven "stdlib" that implements more functionality and saner container classes, and has more freedom to evolve since it's not part of the core JS language. And the justification for using a single-character name is that it's basically a de facto part of the stdlib?