Welcome to the Linux Foundation Forum!

Key JavaScript Concepts | Constructor Functions

Hello,

I'm following Key JavaScript Concepts lesson, and I'm at page 4, where setting up a prototype chain with constructor functions are being studied.

However, I guess there is an issue with the use of util.inherits. When I copy pasted the example first, I got an error stating that:

TypeError [ERR_INVALID_ARG_TYPE]: The "superCtor.prototype" property must be of type object. Received undefined

So I guess, the correct usage is as follows:
util.inherits(Dog, Wolf) instead of util.inherits(Dog.prototype, Wolf.prototype)


Also I guess it would be better if the lesson emphasizes that it is a legacy function and the usage is discouraged. ( https://nodejs.org/docs/latest-v14.x/api/util.html#util_util_inherits_constructor_superconstructor )

Best Answer

  • krave
    krave Posts: 45
    Answer ✓

    I posted the same issue too. util.inherits(Dog, Wolf) should be correct.

Answers

Categories

Upcoming Training