You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.
functionFoo(){}Object.defineProperty(Foo.prototype,'bar',{value: 1,configurable: false,writable: true});Object.defineProperty(Foo.prototype,'bar',{value: 2});// You might expect this to error but it doesn't!
Instead, it only does what you would expect if the descriptor is writable: false or is a getter/setter combo (which doesn't have a writable prop in the descriptor) REPL
functionFoo(){}Object.defineProperty(Foo.prototype,'bar',{value: 1,configurable: false,writable: false});Object.defineProperty(Foo.prototype,'bar',{value: 2});// TypeError: Cannot redefine property: bar
However this also obviously makes the property readonly, which isn't always desired and not the same thing as being nonconfigurable.
varfoo=newFoo();foo.bar=3;// TypeError: Cannot assign to read only property 'bar' of object '#<Foo>'
Most examples I've seen demoing configurable: false omit the writable property all-together, which means it defaults to writable: false so I imagine most haven't noticed this quirk.
The text was updated successfully, but these errors were encountered:
Guessing this is due to an apparent oversight in the spec, since every browser I tried had this behavior.
In raw JS, to show the issue: REPL
Instead, it only does what you would expect if the descriptor is
writable: false
or is a getter/setter combo (which doesn't have awritable
prop in the descriptor) REPLHowever this also obviously makes the property readonly, which isn't always desired and not the same thing as being nonconfigurable.
Most examples I've seen demoing
configurable: false
omit thewritable
property all-together, which means it defaults towritable: false
so I imagine most haven't noticed this quirk.The text was updated successfully, but these errors were encountered: