Or you can write an intermediary function to handle the addition, deletion, modification and query of related variables? Let’s see if others have a better way
var o = {
data : {},
add : function(key,val){
if(!key) return false;
var data = this.data;
data[key] = data[key] || {};
data[key] = val;
},
del : function(key){
if(!key) this.data = {};
delete this.data[key];
},
changeVal : function(obj){
if( Object.prototype.toString.call(obj) != '[object Object]' )
obj = {};
var data = this.data;
for( var key in obj){
if(data[key]){
data[key] = obj;
}
}
}
//.......
//写了个简单的,如果要求更复杂可以自己去拓展
};
It’s a bit difficult to get the value. If you want to assign the value, you can create a new function for the assignment. If you want to modify the value, just call the function directly,
Or you can write an intermediary function to handle the addition, deletion, modification and query of related variables? Let’s see if others have a better way
It’s a bit difficult to get the value. If you want to assign the value, you can create a new function for the assignment. If you want to modify the value, just call the function directly,
Encapsulated into an object