Reputation: 123
I have trouble with my code below.
I have a Object with functions etc and I need a locale storage object too. Is this possible? I always get the "Unexpected identifier" error trying to do this.
var object = {
var STORAGE = new Object();
STORAGE.one = null;
STORAGE.two = null;
STORAGE.three = null;
STORAGE.four = null;
one: function(){
//function one
},
two: function() {
//function 2
}
};
Upvotes: 0
Views: 1600
Reputation: 18354
What you want is achieved like this:
var object = (function(){
var STORAGE = new Object();
STORAGE.one = null;
STORAGE.two = null;
STORAGE.three = null;
STORAGE.four = null;
return {
one: function(){
//function one
},
two: function() {
//function 2
}
};
})();
Cheers
Upvotes: 0
Reputation: 38
Is that what you're looking for?
var object = {
STORAGE: {
one: null,
two: null,
three: null,
four: null
},
one: function(){
//function one
},
two: function() {
//function 2
}
};
Upvotes: 0
Reputation: 239491
You cannot declare variables or run arbitrary code inside an object literal.
You have to use a property:
and a nested object literal:
var object = {
STORAGE: {
one: null,
two: null
// ...
}
one: function () { }
// ...
}
Upvotes: 1