Is there a good way to define a real personal variable in dojo?
In dojo 1.7 / 1.8, I found 2 ways to define a private variable, but both of them are static private (shared by all instances of the class)
1. Use an anonymous immediate function:
define([
'dojo/_base/declare'], function(declare) {
'use strict';
return declare('test.Class2', null, (function(){
var a = 1;
return {
constructor: function(){
console.log('constructor');
},
geta: function(){
return a;
},
seta: function(v){
a = v;
}
};
})());
});
2. Define a personal variable in the module definition.
define([
'dojo/_base/declare'], function(declare) {
'use strict';
var a = 1;
return declare('test.Class1', null, {
constructor: function(){
console.log('constructor');
},
geta: function(){
return a;
},
seta: function(v){
a = v;
}
});
});
source
share