0

I am having some trouble retrieving the getter and setter of a textarea's value property in older browsers, such as Firefox 4 and Chromium 30.

In a nutshell, I am trying to run some code each time a textarea's value is updated programatically, by someone else, like so:

textarea.value="some value";

According to information like https://stackoverflow.com/a/58585971 and https://stackoverflow.com/a/55033939, the only reliable way seems to be this: define new getter and setter for the textarea's value property, with the setter containing the custom code. But, before that, retrieve the original getter and setter and re-purpose them so that the original functionality is preserved.

I am retrieving the descriptor (which contains the getter and setter) like so:

var desc=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value");

or

desc=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(textarea),"value");

or

desc=Object.getOwnPropertyDescriptor(textarea.constructor.prototype,"value");  /* Risky */

or

desc=Object.getOwnPropertyDescriptor(textarea.__proto__,"value");  /* Obsolete */

All of these are retrieving the value descriptor perfectly in any modern browser, including Internet Explorer, but not in older browsers, such as Firefox 4 and Chromium 30 (even though they support all of the above properties and methods). They are returning undefined. In those, HTMLTextAreaElement.prototype does not have a value property, and yet the actual textarea's got them!

How did those browsers implement the value property, if not with getter and setter? Or, how to retrieve them?

a_das
  • 21
  • 3

0 Answers0