Skip to content

Instantly share code, notes, and snippets.

@sonthonaxrk
Last active August 29, 2015 14:18
Show Gist options
  • Save sonthonaxrk/1fe9931fbcbd3cf3093e to your computer and use it in GitHub Desktop.
Save sonthonaxrk/1fe9931fbcbd3cf3093e to your computer and use it in GitHub Desktop.
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;
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 throws the "The Type must be a inherit from JSONResource" error
collection = new JSONResourceCollection("someurl", JSONResource);
@sukima
Copy link

sukima commented Apr 10, 2015

Hmm, I'd look into what JSONResource thinks it is. Maybe a console.dir(JSONResource) on line 2?

@sukima
Copy link

sukima commented Apr 10, 2015

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