                 if (s.length > 0) {
                     s += ", ";
                 }
-                s += prop + "=>" + toString(obj[prop]);
+                s += prop + "=>" + toString(obj[prop], refs);
             }
             return "Object(" + s + ")";
 

    /**
     * Nicely format the specified object into a String.
     */
    public static function toString (obj :*) :String
    {
        if (obj == null) { // checks null or undefined
            return String(obj);
        }

        // TODO: this should be able to detect circular references

        var s :String;
        if (obj is Array) {

                if (ii > 0) {
                    s += ", ";
                }
                s += (ii + ": " + toString(arr[ii], refs));
            }
            return "Array(" + s + ")";

