The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Is there really a way to pass parameters when using addEventListener?

Hi
in my previous research I learnt that you cannot pass parameters when using addEventListener. I did some sort of Google search with the words passing parameters and addEventListener. And came up with people talking in various forums, not this one, that it was not possible to pass parameters to a function evoked with addEventListener. However trying to learn how to make Firefox extensions I came across the below code which seems to do it, however I do not know if this is just a Firefox a XUL or chrome thing. So please look at the code below and give me your verdict.

Also if you just happen to know, is the line" onLoad: function() {" a value property pair? But pleaese do not fail answer my primary question above if you do not know the answer to the second one. So I appreciate your input.
Sincerely
Marc

// this function needs a parameter...function shout (text){alert(text);}// ...however, this will not work:
window.onload= shout("Hello world!");// ...since it will be executed the moment that line is read.// By using a closure, however, you can make it work:
window.onload=function(){
shout ("Hello world!");};

I hope that helps.

Oh, and yes; that is indeed a value property pair. "onLoad" is the name of the property, and the function is actually the value of that property.

So are you saying you can evoke your second function in your example code with addEventListener? The second function as it stands now does not have the word addEventListener in it. Sorry but what you said above just isn't doing it for me. I can go to your link but I would like to understand what you are saying more to convince me that would be worth while.

And you do seem to be able to pass variables to a function evoked with a addEventListener preserving the name space. The link you gave me was very good. I particularly like the line with it stated "In JavaScript, if you declare a function within another function, then the local variables can remain accessible after returning from the function you called." I saw some of the stuff on Closures before but this link was the best explaining it. The code used to prove to concept to myself is posted below if anybody's interested.