if (typeof $ === "undefined") { throw new Error("jQuery is required") } var RecordModel = function(kind, id){ var Record = function() { this.object = null; } Record.prototype.fetch = function(callback, errback) { errback || (errback = function(status, text, xhr){ alert("Error fetching " + kind + ":" + id + " " + status + " " + text); }); var self = this; $.ajax({ url: "/api/" + kind + "/" + encodeURIComponent(id), success: function(data) { self.object = data; callback(self); }, error: function(xhr, textStatus, errorThrown){ errback(xhr.status, errorThrown, xhr); } }); } return new Record(); }