Skip to content

Instantly share code, notes, and snippets.

@heeplr
Last active August 27, 2021 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heeplr/b4ed41bbdf074a5c7f6ec77ece47df5d to your computer and use it in GitHub Desktop.
Save heeplr/b4ed41bbdf074a5c7f6ec77ece47df5d to your computer and use it in GitHub Desktop.
export const Model = BackboneModel.extend({
/* list of read-only attributes */
readOnly: [],
toJSON: function (options) {
/* convert attributes to JSON but omit the ones from "readOnly" */
return _.clone(
return _.omit(BackboneModel.prototype.toJSON.apply(this), this.readOnly)
)
}
})
@jgonggrijp
Copy link

Might want to return _.omit(BackboneModel.prototype.toJSON.apply(this), this.read_only). _.clone is not needed because _.omit already creates a new object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment