#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    132
    Rep Power
    11

    toSource with arrays in IE


    Hi

    Does ie 6.0 implements toSource() method on arrays?

    thanks
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,128
    Rep Power
    4304
    IE6, IE7, and Opera 9 do not support that.

    You can test it with this:
    Code:
    alert('Array.toSource() : '+typeof([].toSource));
    alert('Object.toSource() : '+typeof({}.toSource));
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  4. #3
  5. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,953
    Rep Power
    4033
    It's possible to implement it yourself however.

    Code:
    if (!Object.prototype.toSource){
      Object.prototype.toSource=function(){
        if (this instanceof String){
          return '(new String("'+this.replace(/"/g, '\\"')+'"))';
        }
        var str=(this instanceof Array)
            ? '['
            : (this instanceof Object)
                ? '{'
                : '(';
        for (var i in this){
          if (this[i] != Object.prototype.toSource) {
            if (this instanceof Array == false) {
              str+=(i.match(/\W/))
                  ? '"'+i.replace('"', '\\"')+'":'
                  : i+':';
            }
            if (typeof this[i] == 'string'){
              str+='"'+this[i].replace('"', '\\"');
            }
            else if (this[i] instanceof Date){
              str+='new Date("'+this[i].toGMTString()+'")';
            }
            else if (this[i] instanceof Array || this[i] instanceof Object){
              str+=this[i].toSource();
            }
            else {
              str+=this[i];
            }
            str+=', ';
          }
        };
        str=str.substring(0, str.length-2)+(
            (this instanceof Array)
            ? ']'
            : (this instanceof Object)
                ? '}'
                : ')'
        );
        return str;
      }
    }
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  6. #4
  7. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,128
    Rep Power
    4304
    *whistles* Impressive.

    Did you just now write that yourself?
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  8. #5
  9. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,953
    Rep Power
    4033
    I wrote a simplified version a few months ago that was tailored more to arrays/objects of just strings or numbers. Gave it to someone on IRC at one point to use, and they improved for their usage and sent it back to me.
    Last edited by kicken; September 18th, 2006 at 12:53 PM.
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud

IMN logo majestic logo threadwatch logo seochat tools logo