Using eval(), debugging in general...

    Date: 06/15/05 (Javascript Community)    Keywords: no keywords

    Hello again... I'm back for round 2. Before my other post starts to get off topic, I thought I'd start a new one... on debugging JS. What are your thoughts? Anyone have some tips or tricks?

    I am not totally new to JS, but really haven't used it all that much up until recently. I used to program in C++ at my first job (about 3 years), then I quit there, and at the new job there is a scarcity of anything that cool... the closest I get is JS. But, I'm finding it is almost as fun- despite how tiny it is in comparison. Ok, enough with the boring stuff, here is something I thought was mega cool:

    The eval() function. In conjunction with an or two, it seems to have endless possibilities! Let's say you had a couple text boxes (I like textarea's for this purpose).. named "_input" and "_output". Then you have a button, which will eval() the contents of "_input" and print them to "_output":






    You can now program your JS in the context of the page you're viewing! For example, you could dynamically change the styles on the page using the DOM, or you could alter the values of variables, or even redefine functions. You could enter an entire snippet of JS, provided it is in the right format, and debug it on the fly.

    Examples... type in the box:
    alert('hi'); // and you get an alert!
    myVar01 = 'hi'; // you've just declared a new global var
    alert(myVar01);
    myNewFunc = function(str){alert(str);} // new global func!
    myNewFunc('hello world'); // that you can call right away
    this.myNewFunc; // and retrieve the definition of!
    


    Too cool for me.

    I noticed that in the memories for this journal, someone had posted their own JS console, I'm curious if it was anything like this... but the link is dead now. Thoughts?

    Source: http://www.livejournal.com/community/javascript/69401.html

« global js variables? || Select All checkbox »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home