# Checking if parent class has method defined

**URL:** <https://discuss.emberjs.com/t/checking-if-parent-class-has-method-defined/4153>\
**Category:** Design\
**Created:** [February 13, 2014, 2:22pm UTC](https://discuss.emberjs.com/t/checking-if-parent-class-has-method-defined/4153 "2014-02-13T14:22:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eldo](https://avatars.discourse-cdn.com/v4/letter/e/22d042/32.png) [@eldo](https://discuss.emberjs.com/u/eldo)\
**Post date:** [February 13, 2014, 2:22pm UTC](https://discuss.emberjs.com/t/checking-if-parent-class-has-method-defined/4153/1 "2014-02-13T14:22:44Z")

</div>

What would be a correct way to check if a method is overriding a method from parent class? For example:

```
Ember.Object.createWithMixins({
    foo: function() {
        if (/*Object has foo defined, and our implementation is overriding it) this._super();
        else /* Let's do something else here instead */
    }
})
```

---

<div class="post-metadata">

**Author:** ![jamalsoueidan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jamalsoueidan/32/234_2.png) [@jamalsoueidan](https://discuss.emberjs.com/u/jamalsoueidan)\
**Post date:** [February 13, 2014, 2:39pm UTC](https://discuss.emberjs.com/t/checking-if-parent-class-has-method-defined/4153/2 "2014-02-13T14:39:53Z")

</div>

Maybe something like this?

typeof(this.\_super()) == “function”

---

<div class="post-metadata">

**Author:** ![jimmay5469](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jimmay5469/32/15440_2.png) [@jimmay5469](https://discuss.emberjs.com/u/jimmay5469)\
**Post date:** [February 14, 2014, 3:42pm UTC](https://discuss.emberjs.com/t/checking-if-parent-class-has-method-defined/4153/3 "2014-02-14T15:42:44Z")

</div>

If that doesn’t work, then I would try:

```auto
Ember.Object.createWithMixins({
    foo: function() {
        if (this._super) this._super();
        else /* Let's do something else here instead */
    }
})

```

---

<div class="post-metadata">

**Author:** ![gordon\_kristan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/gordon_kristan/32/14862_2.png) [@gordon\_kristan](https://discuss.emberjs.com/u/gordon_kristan)\
**Post date:** [February 14, 2014, 10:57pm UTC](https://discuss.emberjs.com/t/checking-if-parent-class-has-method-defined/4153/4 "2014-02-14T22:57:58Z")

</div>

`this._super` is always going to be a function. Here’s the code:

```
this._super = superFunc || K;

```

So you’d have to compare against `Em.K` if you wanted to know whether the super function existed or not. Personally, I would use a closure and an instantiated instance of the parent class.

```
Em.Object.create({
    foo: (function(overrides) {
        return function() {
            if (overrides) {} else {}
        };
    })(!!Em.Object.create().foo)
});

```

---

<div class="post-metadata">

**Author:** ![eldo](https://avatars.discourse-cdn.com/v4/letter/e/22d042/32.png) [@eldo](https://discuss.emberjs.com/u/eldo)\
**Post date:** [February 17, 2014, 8:38am UTC](https://discuss.emberjs.com/t/checking-if-parent-class-has-method-defined/4153/5 "2014-02-17T08:38:15Z")

</div>

Thanks for the replies guys. Seems like checking for `this.__nextSuper` does what I like to do. E.g.

```auto
Em.Object.createWithMixins({
    foo: function() {
        if (this.__nextSuper) this._super()
        else /* do something else instead */
    }
});

```

---

<div class="post-metadata">

**Author:** ![gordon\_kristan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/gordon_kristan/32/14862_2.png) [@gordon\_kristan](https://discuss.emberjs.com/u/gordon_kristan)\
**Post date:** [February 21, 2014, 9:07pm UTC](https://discuss.emberjs.com/t/checking-if-parent-class-has-method-defined/4153/6 "2014-02-21T21:07:07Z")

</div>

It should be noted that `__nextSuper` is only defined in the 1.5.0 beta, not in 1.4.0.
