Skip to content

Instantly share code, notes, and snippets.

@nickjacob
Last active November 21, 2023 08:35
Show Gist options
  • Save nickjacob/2314faf0a01b514f16afe61ac7288183 to your computer and use it in GitHub Desktop.
Save nickjacob/2314faf0a01b514f16afe61ac7288183 to your computer and use it in GitHub Desktop.
How to convert an Ember object to a regular javascript object
// an Ember.Object is typeof 'function'/a class
// which can make serialization difficult (e.g., there are issues passing
// to jQuery's serialization
// using Object.assign
// (& es6 syntax)
Ember.Object.reopen({
toNative() {
return Object.assign({}, this);
},
toJson() {
return JSON.stringify(this.toNative());
}
});
// an example obj
const em = Ember.Object.create({ data: [1, 2, 3] });
$.ajax({
type: 'GET',
url: '/api',
data: em.toNative()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment