This function determines a super method dynamically. It returns it as result, but unlike inherited() it doesn’t call it immediately. If there is no super method, a falsy value is returned.
While it is slower than the normal way to do supercalls with
dcl (see the decorator
dcl.superCall() for details), it doesn’t require to modify
a method according to the double function pattern, and can be applied to
undecorated methods, which makes it suitable for fast prototyping, and
transitioning legacy code.
As soon as
inherited.js is included, it mixes in
getInherited() as a method to all
newly created objects, so you don’t need to use the result of the module directly.
getInherited() works in strict mode.
This is a companion method for inherited(). In fact, it is used in its implementation. Just like inherited(), it doesn’t require to decorate a method, and can be used to add a supercall to any arbitrary method, which makes it suitable for transitioning legacy code or fast prototyping:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
As you can see both
getInherited() and dcl.superCall() look
almost identical. The difference is:
- dcl.superCall() works statically and does not incur run-time penalties.
- dcl.superCall() requires a double function pattern described in Supercalls in JS.
For more details please take a look inherited().
When should I use
There are three common scenarios when using
getInherited() is beneficial:
- A method should make several calls to its super method. By using
getInherited()and reusing its result, you save CPU ticks making the whole method faster. For even faster results consider using dcl.superCall().
- Your code behaves differently when there is no super method, and the default provided by inherited() just doesn’t work for you.
- While debugging, you don’t want to go inside inherited()
(it is debugging-friendly, yet you may want to skip it completely while debugging).
In this case you step over calls to
getInherited()and debug your super methods directly.