HTMLElement.prototypeを拡張してinnerTextを実装する

Function.prototypeを拡張して遅延実行を実現するを参考に(というかほとんどパクり)、以下のようなテストコードを書いて実行してみたらうまくいった(Firefoxの場合)。

javascript:(function () {
  Object.extend = function(destination, source) {
    for (property in source) {
      if (source.hasOwnProperty(property)) {
        destination[property] = source[property];
      }
    }
    return destination;
  };
  Object.prototype.extend = function(object) {
    return Object.extend.apply(this, [this, object]);
  };
  HTMLElement.prototype.extend({
    getInnerText: function() {
      if (typeof this.textContent != 'undefined') {
        // DOM3(Firefox)
        return this.textContent;
      } else if (typeof this.innerText != 'undefined') {
        // IE
        return this.innerText;
      } else {
        // Other
        return '';
      }
    }
  });
  var h = document.getElementsByTagName('h1')[0];
  alert(h.getInnerText());
})()

prototypeベースのオブジェクト指向って結構面白いな。