const request = new XMLHttpRequest();
request.open('GET', 'example.php');
request.customVar = 0;
request.onreadystatechange = function(){
this.customVar = this.responseText.length;
const text = `${this.readyState}:${this.customVar}:${this.responseText}`;
document.getElementById('x').innerHTML = text;
};
I have implemented this script in a webpage along with a <p id="x"></p>
. I need to assign a custom variable for usage within the onreadystatechange
function. It works well on the browsers I've tested so far, however, I am unsure if there is a standard naming convention that should be followed for custom variables.
Would it be advisable to prefix custom variables with an underscore or any other specific naming convention? Any guidance on this matter would be appreciated as using member variables feels more appropriate than resorting to global ones (especially since multiple XMLHttpRequest objects might be present on the page).