Reputation: 6008
I used to clone a variable in jquery like this:
var clone = $.extend(true, {}, orig);
Is there any method in Ember.js that is equivalent to this?
Upvotes: 7
Views: 4164
Reputation: 47367
That's like my least favorite named method in jquery. Every time I want to merge two objects it takes me a few seconds of trying to think of what it's called. You can also use assign
in Ember.
Ember.assign({first: 'Tom'}, {last: 'Dale'}); // {first: 'Tom', last: 'Dale'}
var a = {first: 'Yehuda'}, b = {last: 'Katz'};
Ember.assign(a, b); // a == {first: 'Yehuda', last: 'Katz'}, b == {last: 'Katz'}
or in your case
Ember.assign({}, orig);
http://emberjs.com/api/classes/Ember.html#method_assign
But, you should note, it doesn't support deep cloning like copy does.
Upvotes: 18
Reputation: 28587
Yes there is: Ember.copy
var clonedObj = Ember.copy(originalObj, true);
Upvotes: 12