This rabbit hole began as I was investigating
wp, you’ll see a couple of entries. If you do that while viewing a page in the admin, you’ll see a whole lot more and on a page running Gutenberg, you’ll see something like this:
Scrolling down towards the end of the
blocks property, the one I was investigating, I saw something strange:
It looked like each method inside of
blocks was duplicated, dimmed, and prefixed with
get. I decided to dive into this rabbit hole, and started with:
Why are some properties dimmed in a
I’d seen dimmed properties before, and I always thought of them as the properties that are there by default, or ones I’m not supposed to manipulate. It turns out that’s pretty much correct. The technical term for that is that dimmed properties are non-enumerable vs. enumerable properties.
What? This StackOverflow post both identifies the circuitousness of the MDN answer to this question and provides a relatively satisfactory answer. The thing is, sometimes you don’t want every property in an object to be acknowledged when you are looping through an object or an array, and enumerability is the technical word for that.
An array is a great example of what’s enumerable and what’s non-enumerable. When you
console.log an array, you will see a property for
length as well as the expected array entries. We don’t assign the
length is non-enumerable:
This rabbit hole could go much much deeper, but for now I need to get back to my research and figure out what that
get prefix before the blocks means (something to do with getters and setters, I think).
But before I go, a shoutout to the work of Safia Abdalla who blogs about great little development tidbits. Her curiosity and gusto for blog posts are contagious!
Lastly, these resources helped me out:
- The for…in loop from Chris Ferdinandi