Constructors!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zaphod42
    New Member
    • Oct 2008
    • 55

    Constructors!!!

    Does anyone know if you can access/add to the prototype for an elements constructor with javascript? The idea is I would like to add default functionality to certain elements (specifically "Label" elements). The company that this project is for has all of their forms in flat html files that I load with ajax and add to object groups for easier manipulation, it would be really helpful if I could add the methods necessary when the html elements are loaded on the page.

    Right now I just load all the elements currently loaded on the page into an object and iterate through them, applying methods depending on the tagName. It works fine, but after a few forms have been loaded the page obviously slows down. I know how to add to the constructor's prototype of other javascript objects, and I know the constructor for a label element is referenced with "HTMLLabelEleme nt", but I can't seem to affect the prototype...any thought would be appreciated:)
  • rnd me
    Recognized Expert Contributor
    • Jun 2007
    • 427

    #2
    a few examples:

    Code:
    HTMLTextAreaElement.prototype.toString=function(){return this.value}
    HTMLInputElement.prototype.toString=function(){return this.value}
    HTMLTableCellElement.prototype.toString=function(){return this.textContent}
    Element.prototype.__defineGetter__("innerText", function () {return this.textContent.toString()});
    remember that this won't work in IE7 and below...

    Comment

    • zaphod42
      New Member
      • Oct 2008
      • 55

      #3
      that's great, thanks! It just figures that this company would still be using ie6....internat ionally! Get on the ff bus people!

      Comment

      Working...