2 ms·
When I first touched javascript, the most interesting finding was that it didn’t use a hashtable/map for object keys, and also it had no “keys” in a way languag
by wruza 5y ago
When I first touched javascript, the most interesting finding was that it didn’t use a hashtable/map for object keys, and also it had no “keys” in a way languages usually do. Instead every object is a collection of properties, which have:
- name (string or a symbol)
- value -or- getter/setter
- enumerable
- writable
- configurable flags
So for “meta”, instead of catching accesses at the object level, this is usually done at the property level (the former still can be done via proxy). The object’s in-memory structure is also different - not a hash table, but a structure whose directly-addressable fields come in order of properties. This enables some interesting results.
It had disappointing parts as well. You can’t proxy arrays or functions with other kinds of objects, so metaprogramming is limited. That’s why e.g. Vue has restrictions on how you can modify arrays under .data for them to stay observable. It’s sad and that you can’t read details like this in day to day discussions, cause it’s a sign of developers being either unaware or simply not caring (aka Blub paradox). Core limitations like this grow into various covert disabilities of the entire platform, and nobody notices.