Cannot Set Property ... Which Only Has Getter (Javascript Es6)

Cannot Set Property ... Which Only Has Getter (javascript es6)

There are a couple problems here.

When you make a getter via get x() you are causing this.x to result in calling the getter, which will recurse indefinitely due to your get x() doing this.x.

Replace your references to this.x with this._x in this code like this:

class MyClass {
constructor(x) {
this._x = x === undefined ? 0 : x;
}

get x() {
return this._x;
}
}

Now your encapsulated x which is now _x will not be confused for a call to the getter via this.x.

Javascript won't let me set property which only has a getter despite deleting getter

As said in comments, you can't delete what isn't there. password is not a property of user, but of its prototype; so delete user.password does nothing; if you then do user.password = "foo", you will find the property user on the prototype, which is not settable.

Instead, you need to define a property on user itself:

class User {  get password() {    Object.defineProperty(this, "password", {      value: "foo"    });    return this.password;  }};
var user = new User();console.log(user.password);

Uncaught TypeError: Cannot set property playerNo of # which has only a getter on line 4

You have recursion with setting playerNo.

In the playerNo setter, try setting this._playerNo = 0.

In the rest of the code, continue to make a distinction between the name of the setter method and the internal property that stores the data.

How to solve error TypeError: Cannot set property list of #<HTMLInputElement> which has only a getter?

That's because the "list" attribute is read-only and therefore you need to use the setAttribute function to set it/change it.

Try this:

const Input1 = document.createElement('input')
Input1.type = 'text'
Input1.setAttribute("list","car")

Why Memoization in Es6 classes with getters/setters is not working?

The problem is that delete obj[prop] will only "delete" the property prop if it's directly on obj. It will not delete the property if the property is on the internal prototype. For another example: