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.


In reply to Re: Should I learn Perl? -- in defense of Javascript by bart
in thread Should I learn Perl? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.