Javascript function programming — receiving elaborate parameters

Posted by Barney on Stack Overflow See other posts from Stack Overflow or by Barney
Published on 2010-03-28T14:04:03Z Indexed on 2010/03/28 14:13 UTC
Read the original article Hit count: 162

I'm writing a Javascript function that would manipulate an array written on-the-fly and sent as a parameter.

The function is written as follows:

function returnJourney(animation,clean){
    var properties = {};
    // loads of other inane stuff
    for(i in animation[0]) properties[animation[0][i]] = animation[0].i;
    // heaps more inane stuff
}

The animation in question is a set of parameters for a jQuery animation. Typically it takes the format of ({key:value,key:value},speedAsInteger,modifierAsString).

So to kick off initial debugging I call it with:

returnJouney(({'foo':'bar'},3000),1);

And straight off the bat things are way off. As far as I see it this would have returnJourney acknowledge clean === 1, and animation being an array with an object as its first child and the number 3000 as its second.

Firebug tells me animation evaluates as the number 3000. What am I doing wrong?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about functions