Created
February 12, 2014 22:25
-
-
Save adammiller/8965798 to your computer and use it in GitHub Desktop.
This file contains 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
define ["underscore", "backbone" ], (_, Backbone) -> | |
FilteredAttributes = | |
# Instruct toJSON to use a root node | |
rootNode: null | |
# Add attribute names to filteredAttributes to exclude them from JSON | |
filteredAttributes: [] | |
# Process our JSON, excluding filteredAttributes, and using | |
# rootNode if present | |
toJSON: -> | |
json = {} | |
jsonData = Backbone.Model.prototype.oldToJSON.apply @, arguments | |
if @filteredAttributes | |
jsonData = _.omit jsonData, @filteredAttributes | |
if @rootNode | |
json[@rootNode] = jsonData | |
else | |
json = jsonData | |
json | |
Backbone.Model.prototype.oldToJSON = Backbone.Model.prototype.toJSON | |
_.extend Backbone.Model.prototype, FilteredAttributes | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment