JavaScript Ninja – __defineGetter__ and __defineSetter__ advanced methods + Example: Creating innerText Implementation For Browsers That Do Not Have It

/*
 * innerText
 *	Implement innerText for browsers that do not have it.
 */
if (typeof HTMLElement !== "undefined" && HTMLElement.prototype) {
  HTMLElement.prototype.__defineGetter__("innerText", function () {
    var rng = this.ownerDocument.createRange();
    rng.selectNodeContents(this);
    return rng.toString();
  });
  HTMLElement.prototype.__defineSetter__("innerText", function (text) {
    var parsed = document.createTextNode(text);
    this.innerHTML = "";
    this.appendChild(parsed);
  });
}