I want to declare a local variable as such:
(var n=1)
Mostly so I can manipulate the order it gets evaluated in.
Eg Then I could do
var increaseadNumber = (
ar={
inc:function(n){
return n+1
},
dec:function(n){
return n+2
}
}
).inc(1);
console.log(ar)//the object
console.log(increaseadNumber )//2
But, in my example ar is in the global namespace, and
var increaseadNumber = (
var ar={
inc:function(n){
return n+1
},
dec:function(n){
return n+2
}
}
).inc(1);//syntax error
generates “SyntaxError: Unexpected token var”
Granted I could declare this over 2 statements, but I would prefer to it with 1 statement.
Why not separate it into two lines?
And add some sensible white space while you’re at it:
Or if you’re really whitespace-averse, here’s a compromise: