Q about function definition syntax

D

Diogenes

Hi all,

I had a look at sIFR.js code after parsing it and I have a question
about function syntax. For example

var f=function(){
// statements here
}();


What is the purpose if the second set of parentheses following the
closing brace? Is the intention to execute the function immediately
after it has been defined?

Most functions in sIFR.js do not have this syntax, but a few do.

Thanks in advance for your help.

Cheers
Jim
 
T

Thomas 'PointedEars' Lahn

Diogenes said:
var f=function(){
// statements here
}();

What is the purpose if the second set of parentheses following the
closing brace? Is the intention to execute the function immediately
after it has been defined?

Yes, the intention is to assign the function *result* to `f'. The anonymous
function here may be a factory; only the "// statements here" will tell.


PointedEars
 
D

Diogenes

Thanks PE,

I did a search in this newsgroup for 'function' afterwards
(Doh!) and found much the same info, but you said it best.

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,883
Members
47,415
Latest member
SharonCran

Latest Threads

Top