# JS Tip of the Day: super in Object Literals

**URL:** <https://forum.kirupa.com/t/js-tip-of-the-day-super-in-object-literals/643138>\
**Category:** web dev\
**Created:** [March 29, 2020, 12:30pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-super-in-object-literals/643138 "2020-03-29T12:30:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [March 29, 2020, 12:30pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-super-in-object-literals/643138/1 "2020-03-29T12:30:35Z")

</div>

**super in Object Literals**  
Version: ES2015  
Level: Advanced

You may already be familiar with the use of `super` in classes. But you may not already know that `super` can be used in object literals as well. Just like `super` in classes, it will let you refer to inherited methods over methods of the same name in the current instance.

```javascript
let fancyObject = {
    toString () {
        return `~*~${super.toString()}~*~`;
    }
};

console.log(fancyObject.toString()); // ~*~[object Object]~*~

```

In this example, though `fancyObject` defined it’s own `toString()`, it was still able to call its original, inherited (from Object) `toString()` to get the normal string value for objects before making it “fancy” within its own implementation.

`super` in object literals only works for referring to inherited members. There is no `super()` equivalent (`super`, itself, called as a function) in object literals because object literals have no constructor and that format is only for use in constructors.

More info:

- [super in object literals on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super#Using_super.prop_in_object_literals)
