The problem is that writable and set / get are mutually exclusive. The code generates this useful error in Chrome:
Invalid property. A property cannot both have accessors and be writable...
This makes logical sense: if you have set / get attributes for a property, this property will never be written and / or read, because any attempts to read / write it will be intercepted through access functions. If you define a property as writable and provide access functions to it, you simultaneously say:
- "The value of this property can be directly changed" and
- "Block all attempts to read and / or write to this property, use these functions instead."
A mistake just stops you from indicating a contradiction. I suppose from the fact that you wrote a getter and setter, you really don't want the property to be writable . Just delete this line and your code works just fine.
source share