Skip to content

Instantly share code, notes, and snippets.

@thejefflarson
Created June 30, 2010 17:07
Show Gist options
  • Select an option

  • Save thejefflarson/458950 to your computer and use it in GitHub Desktop.

Select an option

Save thejefflarson/458950 to your computer and use it in GitHub Desktop.
// The primary function of a **Model** is to manipulate and query data. For example filtering
// an array-type object should happen in a subclass of Model. Another great candidate
// for a **Model** is any object that requires an external resource such as an ajax call.
//
// Basically, any long running or long blocking operation should happen in a model.
// **Models** are usually encapsulated in **Views** and rarely, if ever, stand alone.
propublica.Model = Base.extend({
// The **init** method copies the passed in attributes to the instance's built in
// **_attrs** object.
init : function(attrs){
this._attrs = this._attrs || {};
_.extend(this._attrs, attrs);
return this;
},
// The **copy** method returns a copy of the current **Model** with the instance's
// attributes filled in.
copy : function(){
return new (this.init)(this._attrs);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment