Skip to content
Advertisement

Uncaught TypeError: class heritage this.MyClass is not an object or null

I’m trying to extend one class from another inside the module. The code looks like that:

JavaScript

in the result console throws the TypeError: Uncaught TypeError: class heritage this.MyClass is not an object or null referring to line *. Could you help me to fix that?

Advertisement

Answer

this is only set when you’re calling a method of the object, it’s not available when you’re initializing an object.

You also can’t refer to the variable af until after the assignment, not during the creation of the literal.

So you need to split this up. Define the first class in the object literal, the rest require assignments so they can refer to the variable.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement