Skip to content

Instantly share code, notes, and snippets.

@formula1
Last active August 29, 2015 14:09
Show Gist options
  • Save formula1/1c12acb2b21beb3943c7 to your computer and use it in GitHub Desktop.
Save formula1/1c12acb2b21beb3943c7 to your computer and use it in GitHub Desktop.
Heres a Completely untested Wrapper
function PathWrapper(path,subs,ctx){
if(typeof ctx == "undefined"){
ctx = subs;
subs = void(0);
}
this.ctx = ctx;
return this.prep(path,subs);
}
PathWrapper.prototype.prep = function(path,subs){
if(/undefined|object/.test(typeof subs))
throw new Error("No Substitution is better than a non-Object Substitution")
if(typeof path !== "string")
throw new Error("If your path is not a string, there isn't a point to this")
this.path = path;
this.subs = subs;
if(this.ctx)
return this.apply(this.ctx);
return this;
}
PathWrapper.prototype.apply = function(ctx){
if(typeof ctx != "object")
throw new Error("Cannot retrieve Values of a Non-Object");
this.ctx = ctx;
this.values = jspath(path,ctx,sctx)
return this;
}
PathWrapper.prototype.delete = function(propertyname){
if(typeof this.values == "undefined")
throw new Error("Cannot delete what doesn't exist");
for(var i in this.values)
delete this.values[i][propertyname]
return this;
}
PathWrapper.prototype.set = function(propertyname, value){
if(typeof this.values == "undefined")
throw new Error("Cannot delete what doesn't exist");
for(var i in this.values)
this.values[i][propertyname] = value
return this;
}
PathWrapper.prototype.get = function(){
if(this.ctx == "undefined")
throw new Error("Please .apply(JSONObject) before attempting to retrieve ")
return this.values;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment