www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 09-18-2003, 10:35 AM
    p3tec's Avatar
    p3tec p3tec is offline
    Registered User
     
    Join Date: Sep 2003
    Location: Bath, UK
    Posts: 2
    Post perl style data dumper for javascript objects

    Hey there - this is my first post here, this seems like the place to post javascripts.

    I'm not sure whether I've gone out on a limb to reinvent the wheel, but I've produced a data dumper, very similar to the one in Perl (here).

    The main function that the user should be interested in is a prototype of Object called dump. It can be fed an optional associative array of options (examples below). The method recursively looks through the object and returns the content of the object (excluding functions)

    I've attached the script (as a txt file), but I've uploaded it to my site as well, so you can use the example below - replace testArray with any object/string/array/number you like
    PHP Code:
    <SCRIPT LANGUAGE="JavaScript" src="http://www.petercracknell.com/include/js/dump.js"></SCRIPT>
    <SCRIPT LANGUAGE="JavaScript" src="dump.js"></SCRIPT>
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    function myFancyObject(asd, sdf, sdf) {
      this.xyzxyz = {
        longword: 4,
        c: [3,5,6],
        d: { w: [3,5] }
      };
      this.abc = [1, 2, 3]
    }

    var testArray = new Array(new myFancyObject(), 4, [4,5]);

    document.write('<pre>');
    document.writeln(testArray.dump());
    document.writeln(testArray.dump({space: '_'}));
    document.writeln(testArray.dump({object_detail: false}));
    document.writeln(testArray.dump({wide_spacing: false}));
    document.writeln(testArray.dump({quote_string: "``"}));
    document.write('</pre>');
    </SCRIPT>

    The script also contains Object.duplicate, Object.isArray, Object.isNumber, Object.isString, which I think are all relatively self-explanatory.

    I'm interested in peoples feedback - I consider these Object functions finished, can anyone see any useful additions? Can anyone find any bugs, problems?

    Finally has this been done before/bettered? I did search google, but couldn't find one.

    Pete
    Attached Files
    File Type: txt dump.txt (7.1 KB, 179 views)
    Reply With Quote
      #2  
    Old 09-18-2003, 05:38 PM
    Jeff Mott's Avatar
    Jeff Mott Jeff Mott is offline
    Super Moderator
     
    Join Date: Jul 2003
    Location: The City of Roses
    Posts: 2,010
    Quote:
    Finally has this been done before/bettered? I did search google, but couldn't find one.
    There's actually one built-in to JavaScript. The toSource() method http://devedge.netscape.com/library/...ence/ix.html#T. Though I don't think Microsoft or Opera has implemented it yet.
    __________________
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

    Last edited by Jeff Mott; 09-18-2003 at 05:41 PM.
    Reply With Quote
      #3  
    Old 09-18-2003, 08:15 PM
    p3tec's Avatar
    p3tec p3tec is offline
    Registered User
     
    Join Date: Sep 2003
    Location: Bath, UK
    Posts: 2
    Cool, so eventually there should be some proper data dumping, but I take it that'll be a while before that gets to be the norm.

    My code is only really for developers - I can't believe no one else has written anything similar!?! I use the equivalent in perl on a daily basis at work and couldn't imagine developing without it (obviously there are differences between the language and its usage).

    Now (I at least) have a tool to see what's really going on with my objects/data - in my current project (3d modeller, still in alpha), I have a frame that is constantly pumped the data dumpers output, so I know what's going on.

    Any comments/suggestions?

    Pete
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 07:46 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.