Why can't get and set in Object.defineProperty () be used with writable?

Why can"t get and set be used with writable in

Object.defineProperty () will report an error

var obj = {}
Object.defineProperty(obj, "name", {
  configurable: true,
  enumerable: true,
  writable: true,
  value: 2,
  set(value) {
    name = value
  },
  get() {
    return value
  }
})
obj.name = 2
console.log(obj.name)

if the code above, it will report Cannot both specify accessors and a value or writable attribute this error
solve

May.06,2021

if a descriptor does not have either value,writable,get or set keywords, it is considered a data descriptor. If a descriptor has both (value or writable) and (get or set) keywords, an exception will be generated. -taken from the original words of MDN.

probably means that it is impossible to set an attribute that can read and write it normally, and you can set a layer of getter/setter on it to access and rewrite it.

MDN address > https://developer.mozilla.org.

Mobile phone code words, excuse me (escape

Menu