Skip to content

Instantly share code, notes, and snippets.

@hughfdjackson
Created February 4, 2013 19:06
Show Gist options
  • Select an option

  • Save hughfdjackson/4708784 to your computer and use it in GitHub Desktop.

Select an option

Save hughfdjackson/4708784 to your computer and use it in GitHub Desktop.
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 ;-;
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