0

below is function i want to use

(function () {
  var url = param_url;
})(); // what are these ending curly brackets for ?
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
Yasir
  • 3,817
  • 10
  • 35
  • 41
  • possible duplicate of [What does this javascript syntax mean?](http://stackoverflow.com/questions/511096/what-does-this-javascript-syntax-mean) – outis Dec 11 '10 at 08:20

1 Answers1

1

The ending parentheses (()) call the function. You can pass arguments to it by putting them within the parentheses.

What you have there is a function expression which is then immediately called. The function expression is:

(function () { var url = param_url; })

...and then the parens call it. it's the same as:

var v = function () { var url = param_url; };
v();

...aside from the use of v, of course. So to pass an argument to it, just do this:

(function (argname) { var url = param_url; })(your_argument_here);

kangax has written up a useful article on function expressions, including browser bugs related to naming the function in the expression (amongst other things), which you should be able to but sadly, can't currently.

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875