Loading ...
Sorry, an error occurred while loading the content.

Lessons from the "Subversion Links" Greasemonkey Script

Expand Messages
  • Shlomi Fish
    Hi all! Recently I worked on the Subversion Links Greasemonkey script: http://www.shlomifish.org/open-source/bits-and-bobs/greasemonkey/grease.html I
    Message 1 of 1 , Oct 6, 2008
    • 0 Attachment
      Hi all!

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


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

      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

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

      for (i in myarray)

      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.


      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
    Your message has been successfully submitted and would be delivered to recipients shortly.