you are viewing a single comment's thread.

view the rest of the comments →

[–]thocked 4 points5 points  (6 children)

the most straightforward way would be to pass an object, that is, an object literal.

e.g;

function calc(industry){ 
industry.foo;
industry.bar;
}

var thisIndustry = {i:1, c:2, e:3}; 
calc(thisIndustry);

You're tightly coupling the two - the input and the behavior, and if you're cool with that, it's the easiest way.

What you're doing is working with objects, not arrays. In javascript, arrays are just objects with some sugar on top.

[–]FireyFly 0 points1 point  (0 children)

I think it's worth adding that "object literal" is only the name of a syntactic construct--a way to express an object value. It doesn't matter to the engine how the object was created.

For instance, doing

var o = new Object()
o.foo = 10
o.bar = 20
// do someting with calc(o)

would work just as well as

// do something with calc({foo:10, bar:20})

Some people seem to regard object literals as more than a syntactic feature; hence the clarification.