Welcome to the Linux Foundation Forum!

Lab 5.2 - Prototypal Inheritance

Options

The instructions specify:

// TODO:
// implement a way to create a prototype chain
// of leopard -> lynx -> cat
// leopard prototype must have ONLY a hiss method
// lynx prototype must have ONLY a purr method
// cat prototype must have ONLY a meow method

const felix = null //TODO replace null with instantiation of a cat

I find the lab instructions somewhat confusing. It is not clear whether the goal is merely to establish a prototype chain or to define constructor functions for Cat, Lynx, and Leopard, in addition to establishing the prototype chain.

Moreover, the description of the inheritance chain raises questions. Typically, one would expect both leopard and lynx to inherit functionalities from cat, implying that they are more specialized forms of a cat. However, the instruction that felix should be an instantiation of a cat, rather than a derivative contradicts this expectation.

An explanation of the intended inheritance hierarchy would be helpful, as the current instructions seem to suggest an unusual structure.

Answers

  • xdxmxc
    xdxmxc Posts: 148
    Options

    @itaid that is the nature of the language, you can answer that question in about 5 or 6 ways, the most conventional contemporary approach would prob just use the class syntax but JavaScript isn't class-based it's prototype-based - and that's the point of wording it this way - it's extremely important not to think of JavaScript classes as classes in any other language because they behave very differently. It's better to consider the prototypal nature, it's just objects pointing at objects, and think of the class syntax as sugar for creating objects that point at objects (which is exactly what it is)

  • itaid
    itaid Posts: 11
    Options

    Sorry, that's not the point ... the hierarchy in the lab makes no sense.

Categories

Upcoming Training