0

What object will this create? I've never seen this declaration before so I'm just wondering.

`myArray([]);
 for(someValue = 0; someValue < someOtherValue; i++)
 myArray.push(something[i]);
`

Thanks for any insight you can give me.

EDIT : I Update the code some more to gime some more info. myArray doesn't seem like a function to me in the code. This is used in an AjaxCall. Some lines after it is used like this

So unless I missed something I don't think it is a function.

asked Feb 19, 2013 at 15:33
4
  • Probably an object of type myArray. Commented Feb 19, 2013 at 15:33
  • [] is an array literal. What is that myArray function? Commented Feb 19, 2013 at 15:34
  • it's a function call with an empty array as an argument Commented Feb 19, 2013 at 15:34
  • Exactly what I'm wondering. Looks like an array to me. Commented Feb 20, 2013 at 14:40

3 Answers 3

3

[] is an empty array literal and it's being passed to a function myArray which accepts an array as an argument. This is not a declaration, it's just a function call. It could be defined like this:

function myArray(array) {
 for (var i = 0; i < 5; i++) {
 array[i] = i;
 }
}
var array = []; // empty array to be filled later
myArray(array);

This fills the array with the numbers from 0 to 4.

answered Feb 19, 2013 at 15:34
Sign up to request clarification or add additional context in comments.

Comments

1

You're calling the function myArray and passing in any empty array literal, which is defined by these: []. What's the myArray function look like?

answered Feb 19, 2013 at 15:35

Comments

1

If myArray is a function you are calling then [] will pass an empty array as the first argument to it

Its same as doing

var arr = new Array();
myArray(arr);
answered Feb 19, 2013 at 15:35

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.