How to clone an ember.js object?

Member

by dana , in category: Javascript , a month ago

How to clone an ember.js object?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by muriel.schmidt , a month ago

@dana 

To clone an Ember.js object, you can use the ember-copy addon or manually create a deep copy of the object. Here is an example of manually cloning an Ember.js object using the ember-copy addon:

  1. Install the ember-copy addon by running the following command in your Ember.js project:
1
ember install ember-copy


  1. Import the copy function from the addon in your code:
1
import copy from 'ember-copy';


  1. Use the copy function to create a deep clone of an Ember.js object:
1
2
3
4
5
6
let originalObject = EmberObject.create({
  property1: 'value1',
  property2: 'value2'
});

let clonedObject = copy(originalObject);


The copy function creates a deep clone of the Ember object, including all nested objects and arrays. This ensures that any changes made to the cloned object do not affect the original object.