1

What does this construct mean?

var digits = [1, 2, 3];

(function fetchData(name){
 //body
})(digits.shift());
0

3 Answers 3

2

That syntax is used to prevent identifiers from leaking into the containing namespace.

After that code, if you attempt to call fetchData(name) you will find that fetchData is undefined, thanks to the () wrapper.

Sign up to request clarification or add additional context in comments.

Comments

2

which construct?

I can explain what's happening, if that will help:

(in the order of execution)

  1. array gets created and assigned the name of "digits"
  2. the first element of "digits" gets removed from the array - so the length of the array gets reduced
  3. that value that got removed gets passed as an argument into the function fetchData() as the variable "name"

Comments

1

Declare a function and call it.

Click on this http://jsfiddle.net/TC8K6/ you will see a alert of the parameter passed to the function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.