8 Replies Latest reply on Mar 19, 2010 12:15 AM by Harbs.

    toString() overrides in constructor-less classes? [CS3,JS]

    John Hawkinson Level 5

      How do I override the toString() method in a class that lacks its own constructor?

      (I'm actually working with the ManagedArticle class from Woodwing's SmartConnection plugin, but the probem appears to be general for any such class, so here we are with Page).




      Page.prototype.toString = function() {
           return "[object Page "+this.name+"]";
      p0 = app.activeDocument.pages[0];
      $.writeln("1: "+p0);
      $.writeln("2: "+p0.toString());
      $.writeln("3: "+Page.prototype.toString.call(p0));
      p1 = app.activeDocument.pages.add();
      $.writeln("4: "+p1);
      $.writeln("5: "+p1.toString());
      $.writeln("6: "+Page.prototype.toString.call(p1));



      1: [object Page]
      2: [object Page]
      3: [object Page 1]
      4: [object Page]
      5: [object Page]
      6: [object Page 2]


      Is this a fool's errand? I'd really like easier debugging of this class and overriding the toString() would seem to be the way-to-go.