I, too, was curious about this, so I decided to run some code in the console! It looks like both spread and assign will copy "normal" getters, but they will not copy getters that are explicitly marked as non-enumerable using Object.defineProperty or Reflect.defineProperty:
However, when an object is an instance of a class that defines a getter, the getter is on the object's prototype and so it doesn't show up during enumeration and therefore doesn't get copied with object spread/assign:
I, too, was curious about this, so I decided to run some code in the console! It looks like both spread and
assign
will copy "normal" getters, but they will not copy getters that are explicitly marked as non-enumerable usingObject.defineProperty
orReflect.defineProperty
:However, when an object is an instance of a class that defines a getter, the getter is on the object's prototype and so it doesn't show up during enumeration and therefore doesn't get copied with object spread/
assign
:I would assume this behavior to be consistent with setters.