[Israel.pm] Lessons from the "Subversion Links" Greasemonkey Script

Shlomi Fish shlomif at iglu.org.il
Mon Oct 6 11:53:42 PDT 2008


Hi all!

Recently I worked on the "Subversion Links" Greasemonkey script:

http://www.shlomifish.org/open-source/bits-and-bobs/greasemonkey/grease.html

I naturally wrote it in JavaScript, and ran into a few problems while doing 
so:

1. I discovered that the "for (item in array)" loop loops over the keys of the 
array (whether numeric or strings) and as a result, doesn't work like in 
Perl:

<<<<<<
var myarray = ["One", "Two", "Three", "Four"];

for (i in myarray)
{
	alert(i);
}
>>>>>>

Will alert 0, 1, 2, 3. To implement the Perl behaviour, one should use 
"item = myarray[i];". 

2. I was told the syntax for initialising an associative array was 

{{{
["key1" => "value1", "key2" => "value2"]
}}}

But as it turns out it is:

<<<
{ "key1" : "value1", "key2":"value2" }
>>>

Integral arrays can be initialised with ["Zero", "One", "Two", "Three"], etc.

3. I tried doing something like this:

<<<
{ "item" : function (p) { return
"Hello " + p;
}
>>>

But the "return" returned immediately without consulting the other expression. 
As it turns out, semicolons are optional in JavaScript, and a newline may 
terminate an expression. I had to put the "return" in its own line.

----------

All of these things delayed the finish of the script.

Regards,

	Shlomi Fish

-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

Shlomi, so what are you working on? Working on a new wiki about unit testing 
fortunes in freecell? -- Ran Eilam



More information about the Perl mailing list