How to create a duplicate of an object (obj.dup)


#1

How do I create a duplicate of an object?

obj1 = Ember.Object.create({name: "Sample"});
obj2 = obj1;
obj2.set('name', 'different');
obj1.get('name');  // different

Any method similar to obj2 = obj1.dup ?


Duplicate an object of an Ember Data model
#2

Look into http://emberjs.com/api/classes/Ember.Copyable.html


#3

Yeah, saw that but din understand how to use the mix on an ember object. Could you give an example please?


#4

use this

http://jsfiddle.net/e4nZE/

copy(object, true); // 2nd argument deep copying.