const parent = { parentProp: true, sayHi: () => console.log('Hello') } const child = { greet: () => super.sayHi() } Object.setPrototypeOf(child, parent) child.greet() 

Uncaught SyntaxError: 'super' keyword unexpected here

Question:

  1. As I understand it, the interpreter swears that super unacceptable inside the switch functions, but why ?
  2. Is it possible to somehow create a custom solution that replicates the super functionality? For example, _super.method()
  • greet () { super.sayHi()} solves the problem - Grundy

1 answer 1

On the first question. Archery nothing to do with. super cannot be used in functions that are properties — only in full-fledged methods. This is due to the fact that when accessing via super, the [[HomeObject]] of the current method is used, and __proto__ is taken from it.

Read more here: https://learn.javascript.ru/es-object#super

On the second question, it is not quite clear why you need this. Just in your code, replace the switch function with

 greet() {super.sayHi()}