below is function i want to use
(function () {
var url = param_url;
})(); // what are these ending curly brackets for ?
below is function i want to use
(function () {
var url = param_url;
})(); // what are these ending curly brackets for ?
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.