@noracodes yeah, getters and setters are applied at a very low level in JS/TS

technically the way to understand it is that there are two kinds of properties, “data properties” and “accessor properties”. data properties have values. accessor properties do not have values, they only have accessor methods. so *anything which tries to modify that property will go through that method

(* of course, because things aren’t quite that simple, it is possible [altho hard] to overwrite an accessor property with a data property, and also possible [and somewhat easier] to shadow it further down in the prototype chain. but most JS methods do not do this)

@noracodes (actually, i think what is easy is shadowing data properties with other data properties, i think shadowing accessor properties is intentionally hard precisely so that things like Object.assign don’t accidentally do it)

Follow

@noracodes (but if you have

class A {}
A.prototype.value = "etaoin"
const a = new A()
a.value // "etaoin"

a.value = "shrdlu"
a.value // "shrdlu"

this creates a new data property on `a` instead of modifying the existing data property on `A.prototype`. this is more information than you were asking for tho haha)

· · Web · 0 · 0 · 1
Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.