Skip to content
Advertisement

Javascript – How do I have a get/set in a method? (e.g. pineapple.is_a.fruit)

I have an assignment where I’m supposed to make magic out of programming. I’m unable to find any answers online, as I do not know the search term for it (tried method in a method etc…). Appreciate any help given!

Here’s what I got: I need to create a class that builds upon itself. e.g.

JavaScript

I do not even know where to begin. My attempt is similar to this, but I’m getting undefined.

JavaScript

Advertisement

Answer

Assuming that they can be defined in advance, in order to have sub-properties like pineapple.is_a.fruit, you’ll need to define objects on the object’s is_a and is properties. For instance (see comments):

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