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?
Ember has been historically coupled to jQuery. As part of RFC294, jQuery has been made optional. This addon makes jQuery available in an Ember project. It also provides the mechanism that implements jQuery integration when that feature is enabled.
The jQuery. extend() method is used to merge contents of two or more objects together. The object is merged into the first object.
js is an open-source JavaScript web framework, utilizing a component-service pattern. It allows developers to create scalable single-page web applications by incorporating common idioms, best practices, and patterns from other single-page-app ecosystem patterns into the framework.
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.
Yes there is: Ember.copy
var clonedObj = Ember.copy(originalObj, true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With