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); |
function Foo() {}
function validateFoo(Type) {
if (Type.prototype.isPrototypeOf(new Foo())) {
return true;
} else {
throw new TypeError('Must be a Foo');
}
}
console.log(validateFoo(Foo));
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm, I'd look into what JSONResource thinks it is. Maybe a
console.dir(JSONResource)
on line 2?