0

Im trying to set the property called offsetWidth, i know that field isn't writeable (read only) by default but if i make a setter it will be writeable, rigth ?

If with a setter it stores the value, why it isn't store ?

If for example i debug in this.offsetWidth = v; (inside of defined setter) this.offsetWidth for example is 565 and v is 666, after make next step in debug the value isn't change, my question is why ?

var nativeOffsetWidth4 = Object.getOwnPropertyDescriptor(HTMLElement.prototype,'offsetWidth');

nativeOffsetWidth4.get= function(){
    console.log(this.offsetWidth);
}

nativeOffsetWidth4.set= function(v){
    this.offsetWidth = v;
}

nativeOffsetWidth4.get.call(document.body);

nativeOffsetWidth4.value = 666; //Don't stores the value.

nativeOffsetWidth4.get.call(document.body);

nativeOffsetWidth4.set.call(document.body, 666); //Don't stores the value.

nativeOffsetWidth4.get.call(document.body);
  • 1
    Why are you insisting on setting a readonly attribute? Just change the element width and the offsetWidth will change – Kinglish Jun 17 '21 at 17:52
  • 1
    https://stackoverflow.com/a/21064102/1772933 – Kinglish Jun 17 '21 at 18:00
  • OK, now i have it more clear about property alias, the difference of they are the type is integer and inchangeable because read only, i knew they are read only, but i think it was possible to force the change, but for what im seeing, no. Thanks @Kinglish! – Alumno Cabreado Jun 17 '21 at 18:20

0 Answers0