Is there a way to apply a two-dimensional array to an object?
Like this:
var myArray = [[0,1],[2,3]];
someObject.apply(null,myArray);
It seems to apply only the first inner array :-/
Why is that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Okay, since your question was so uninformative I’m going to assume a lot of stuff. Firstly, I’m going to assume that
someObjectis a function. Next I’m going to assume that it has only one formal parameter like @Adam pointed out. So this is what I assume your code looks like:This is what I think you want instead:
Remember, when you
applyarguments to a function you pass it the arguments as an array. It’s kind of like calling the function as follows:Of course, it also assigns the function a custom this pointer.
Edit: Looking back at your code I think you might have intended to use
callinstead ofapply. The methodcallallows you to pass the arguments to the function as separate arguments instead of an array of arguments. So your code would look: