Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Friday, November 12, 2010

bookmarklets

The reason bookmarklet links in web pages have void() round them is that void is a JS keyword which evaluates its argument and doesn't return anything (or returns undefined according to who you believe). If this is not used, the browser will replace the document in which the javascript: link was evaluated, with the result of the evaluation, which is generally not what you want.

NB that while javascript: URLs can contain whole chunks of code, void expects an expression, not a block or series of statements. So code of any complexity inside void needs to be inside an anonymous function evaluation.

While I'm on, the anonymous function syntax is thus

(function () { code; more code; })()

From the inside out, you have a block of code in {}, which is being used to construct a function with no arguments - function () - and that function definition has ( ) round it, and then it is being evaluated with no arguments, hence the trailing ().

Btw Firefox will take quite a lot of text in a javascript: URL. You can paste it in from a file with line breaks etc and FF doesn't care.

However, using a drop-line comment // seems to give it a headache. It probably thinks you're trying to say javascript://blah .

C-style block comments seem fine though.

Followers

Blog Archive