Created
February 4, 2013 19:06
-
-
Save hughfdjackson/4708784 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var MyModel = Backbone.Model.extend({ | |
| urlRoot: '/wibble', | |
| clone: function(){ | |
| var attrs = _.chain(this.attributes).omit('id', 'cid').clone().value() | |
| return new this.constructor(attrs) | |
| } | |
| }) | |
| var m1 = new MyModel() | |
| m1.save({ | |
| foo: { bar: { quux: 'bizzle' } } | |
| }) | |
| var m2 = m1.clone() | |
| m2.get('foo').bar = 'baz' | |
| m1.get('foo').bar // 'baz' - d'oh ;-; |
This file contains hidden or 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
| var MyModel = Backbone.Model.extend({ | |
| urlRoot: '/wibble', | |
| clone: function(){ | |
| var attrs = _.chain(this.attributes).omit('id', 'cid').cloneDeep().value() | |
| return new this.constructor(attrs) | |
| } | |
| }) | |
| var m1 = new MyModel() | |
| m1.save({ | |
| foo: { bar: { quux: 'bizzle' } } | |
| }) | |
| var m2 = m1.clone() | |
| m2.get('foo').bar = 'baz' | |
| m1.get('foo').bar // { quux: 'bizzle' } - hurrah |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment