Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of jQuery $.extend() in Ember.js?

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?

like image 369
Melvin Avatar asked Jun 18 '14 10:06

Melvin


People also ask

Does Ember use jQuery?

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.

What is jQuery extend?

The jQuery. extend() method is used to merge contents of two or more objects together. The object is merged into the first object.

What is the use of Ember JS?

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.


Video Answer


2 Answers

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.

like image 178
Kingpin2k Avatar answered Oct 22 '22 19:10

Kingpin2k


Yes there is: Ember.copy

var clonedObj = Ember.copy(originalObj, true);
like image 40
bguiz Avatar answered Oct 22 '22 19:10

bguiz