jweinst1
5/16/2016 - 9:52 PM

new variable dict for json language

new variable dict for json language

//class to implement variable collection and storage
var Vardict = (function(){
	//private object to hold values in the dictionary
	function Valobj(value){
		this.value = value;
	}
	function Vardict(){
		
	}
	Vardict.prototype.init = function(key, value){
		this[key] = new Valobj(value);
	};
	Vardict.prototype.del = function(key){
		delete this[key];
	};
	Vardict.prototype.check = function(key){
		return key in this;
	};
	//gets the entire value with it's object reference
	Vardict.prototype.get = function(key){
		if(this.check(key)){
			return this[key];
		}
		else{
			return false;
		}
	};
	//gets only the value associated with the reference
	Vardict.prototype.getValue = function(key){
		if(this.check(key)){
			return this[key].value;
		}
		else{
			return false;
		}
	};
	//modifies the value of a preexisting object
	Vardict.prototype.set = function(key, value){
		if(this.check(key)){
			this[key].value = value;
		}
		else {
			return false;
		}
	};
	return Vardict;
})();
/*   var a = new Vardict();
   a
=> {}
   a.init("foo", 55)
   a
=> { foo: { value: 55 } }
   a.get("foo")
=> { value: 55 }
   a
=> { foo: { value: 55 } }
   a.set("foo", 4)
   a
=> { foo: { value: 4 } }
   a.del("foo")
   a
=> {}*/