First possibility
You could try doing this but as I haven't developed anything using ImpactJS it may not work as expected as it depends what the .class.extend()
function does internally.
But it's worth a try.
var ServerData = ig.class.Extend((function() {
var privateVar = -1;
return {
getVariable: function() {
return privateVar;
},
setVariable: function(value) {
privateVar = value;
}
};
})());
This code may seem a bit confusing to you, but what I've changed I've created an immediately executing function to create a function closure, which is required to create private space in which I created private to closure variable that's not visible outside.
I would suggest you to read Douglas Crockford's Javascript and learn even more stuff about the language you're using.
Second possibility
According to link in comments it seems that we can use define
's closure for private members as well:
var privateVar = -1;
var ServerData = ig.class.Extend({
getVariable: function() {
return privateVar;
},
setVariable: function(value) {
privateVar = value;
}
});