Last active
August 29, 2015 14:18
-
-
Save sonthonaxrk/1fe9931fbcbd3cf3093e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function JSONResource(obj) { | |
this._watchFields = new Array(); | |
this._serverCopy = obj; | |
for (var field in obj) { | |
if (obj.hasOwnProperty(field)) { | |
this._watchFields.push(field); | |
this[field] = obj[field]; | |
} | |
} | |
} | |
module.exports = JSONResource; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var JSONResource = require('./JSONResource'); | |
encodeObj = function(obj) { | |
var str = []; | |
for(var p in obj) | |
if (obj.hasOwnProperty(p)) { | |
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); | |
} | |
return str.join("&"); | |
} | |
function JSONResourceCollection(source, Type) { | |
if (Type instanceof JSONResource) { | |
this.Type = Type; | |
} else { | |
throw "The Type must be a inherit from JSONResource"; | |
} | |
this.source = source; | |
this._queryStr = new String(); | |
this.query = new Object(); | |
this._collection = new Array(); | |
} | |
module.exports.JSONResourceColleciton; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This throws the "The Type must be a inherit from JSONResource" error | |
collection = new JSONResourceCollection("someurl", JSONResource); |
sukima
commented
Apr 10, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment