Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if object is Ember Data or not

In Ember.js, I need to write a function that behaves differently depending on whether an object is an Ember Data object, or something else (Ember Object, plain JSON object, etc.). Is there a way to determine whether an object is Ember Data or not?

myfunction(myObject) {
    if(isEmberData(myObject)) {
        // Do stuff
    } else {
        // Do something else
    }
}
like image 535
manwill Avatar asked Jun 04 '26 10:06

manwill


1 Answers

A simple

if (obj instanceof DS.Model) {}

Should do the trick.

like image 181
Lux Avatar answered Jun 07 '26 01:06

Lux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!