in reply to Should I learn Perl?

JavaScript is just a pain in the *ss... to do anything actually relevant, you have to write a phone book...

I feel like I have to come to the defense of Javascript here... there isn't much that you can do in Perl that you can't do in Javascript. Featurewise, JS appears to have borrowed a lot from Perl.

For example, here's a little yet powerful introspection function that can aid you in inspecting properties of Javascript objects.

function enumerate (obj, re) { var r = ''; for (p in obj) { if((re==null || p.match(re)) && p!='filters') { var s = '' + obj[p]; r += p + ":\t" + s + "\n"; } } return r; }

n.b. The "filters" property is something I've only seen in MSIE. It just gives an error if you try to access its value (as a string). That's why I just skip it.

Wrap this between "<script>" tags... An example on how to call it, in a HTML document:

<button onclick="javascript:alert(enumerate(document.body));"><b>all</ +b> body properties</button> <button onclick="javascript:alert(enumerate(document.body, /width/i)); +">width related body properties</button>
This works well (tested) both in Mozilla 1.2 for Windows and MSIE 5.5. As you click on the "all properties" button, you'll see far too many properties to even all show up in the alert box. That's why I provide a property name based filtering mechanism, using an optional regular expression.

It's all there: optional arguments, regexps as native objects — just like passing a qr// argument in perl, objects which are actually hashes...

Before you slug on JavaScript any further, please look into a good book on the subject... I know there are more crappy than decent books on Javascript, just like on CGI. The Javascript book from O'Reilly is quite good. I'm not even suggesting that you should buy it, just checking it out is good enough for me.

Replies are listed 'Best First'.
Re: Re: Should I learn Perl? -- in defense of Javascript
by tachyon (Chancellor) on Mar 09, 2003 at 22:48 UTC

    there isn't much that you can do in Perl that you can't do in Javascript.

    This is a joke right? You don't see a lot of browser depentdent 500 Internal server errors but I have lost count of all the offers to debug dysfuntional javascript/Jsctipt I have seen..... Javascript was of course castrated from birth in terms of available functionality.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Re: Should I learn Perl? -- in defense of Javascript
by Anonymous Monk on Mar 09, 2003 at 20:20 UTC

    I think most of the opposition to javascript comes from certain large companies not supporting it properly in their web browsers, which leads to lots of tedious workarounds.

Re: Re: Should I learn Perl? -- in defense of Javascript
by Anonymous Monk on Mar 10, 2003 at 06:29 UTC
    OK, point made. To be fair, I am probably heavily biased against it due to finding bad books... most of them that I have seen focus on the event handlers, and have only really listed uses such as rollovers, scrolling marques and such. The BEST book I have on JavaScript atm has multiple chapters on doin image rollovers (controlling one rollover from multiple links, controlling multiple rollovers from one link, Using a function to code multiple images with a single rollover, Cycling banners, etc... goes on for almost forever)


    Assuming that my bad taste for JS is caused by bad books; What is the cure? Anything out there treat this language as anything but an HTML add-on? O'Reilly looks like it has been mentioned here with every post... I gotta buy stock in that place.


    Me