5

I tried doing this:

var1, var2, var3 = {}

and only the last var was an object, is i posible to create multiple empty objects or arrays without doing

var all = {}, used = {}, unused = {};

?

3
  • nope. weeell, it's more complicated than var var1={}, var2={} anyway... Commented May 1, 2013 at 11:49
  • 2
    Why you really need that? You have written the correct method and asking us for an answer! Commented May 1, 2013 at 11:49
  • 1
    The short answer is no , what you're doing (in the second method) is the correct way to do this. If your variables are sequential (like var1 var2 var3...) you should use an array but from your second code snippet that does not seem to be the case. Commented May 4, 2013 at 13:22

1 Answer 1

3

What you wrote is similar to :

var1;
var2;
var3 = {};

What you need is :

var1 = var2 = var3 = {};
Sign up to request clarification or add additional context in comments.

2 Comments

-1; only 1 object with 3 variables referencing to it will be created. and my eyes bleed from use of global variables.
@Pavel - These are not 3 different objects. They are one. Making change in either of these references will reflect in all of them.

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.