Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Tuesday October 18, 2005
01:09 PM

Javascript feels like Perl

[ #27229 ]

I really have to admire how Perlish Javascript seems to be at times. Of course, that could be how I'm using it:

_getComparison: function (elem, type) {
    var name  = elem.name;
    var regex = new RegExp("^_([^_]*)_" + type);
    name      = name.replace(regex, "$1");

    if (! name) return;
    var value = "";
    if (elem.options) {
        value = elem.options[elem.selectedIndex].value;
        value = value ? value : "";
    }
    return {
        "name"  : name,
        "value" : value
    };
},

Oh, but that's a bit complicated. I had better have tests.

canOK('FormHandler.Search', '_getComparison');
var elem = document.search._age_comp;
var results = search._getComparison(elem, 'comp');
is(results["name"], "age",
  '... and it should return the name of the property it refers to');
is(results["value"], "GT",
  '... and the value of the comparison property');

elem = document.search._age_logical;
results = search._getComparison(elem, 'logical');
is(results["name"], "age",
  '... and a logical comparison should return the property name');
is(results["value"], "",
  '... but it should return an empty string if there is no value');

And the results:

ok 18 - FormHandler.Search.can('_getComparison')
ok 19 - ... and it should return the name of the property it refers to
ok 20 - ... and the value of the comparison property
ok 21 - ... and a logical comparison should return the property name
ok 22 - ... but it should return an empty string if there is no value

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.