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:
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.<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>
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |