Question

(function(aLeftPane) { ... }) ("History").

The complete function is here: pastebin.com

I haven't been able to get my head round how the contents of the seconds set of brackets gets passed into the functions in the first set.

I want to make the hard-coded "History" into a variable. I've tried wrapping the whole thing in a more regular function, but I haven't been able to pass parameters to it successfully.

The XUL that calls the function currently looks like this: oncommand="madeUpWrapperName('history');"

Was it helpful?

Solution

(function(aLeftPane) { ... }) ("History")

Is not an unusually structured function, it's a common pattern to encapsulate code in JS. What it does is declare an anonymous function and then immediately call it. It is used very often by libraries to create the lib entry point and cleanly separate private from public code without polluting the global namespace.

In your case, you actually want to unwrap the function :

function unwrapped(aLeftPane) 
{
    /**
     * Select left panel in Library.
     *
     * @param aBrowser Browser object in selected tab.
    ...

}

then, in your xul or somewhere else:

oncommand="unwrapped('History');"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top