Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Implement Instance Of (Main Thread)

Here is the interview question prompt, presented for reference.

In Object-Oriented programming, an instance represents an object which is an instantiation of a class. An object can also be an instance of a given class A if it is instantiated from a class B that extends the class A.

In a non-programming context, you could think of "cat" as a class and your particular cat as an instance of that class.

Many object-oriented programming languages have a built-in way of checking if a given object is an instance of a given class, and in Javascript this can be achieved by checking if the prototype property of a constructor appears anywhere in the prototype chain of an object.

Can you implement a function that will check if an object is an instance of a class, and will accept the object and the class as parameters?

The function should work like the following example:

class A {}
class B extends A {}

let objB = new B()
instanceOfClass(objB , B) // true
instanceOfClass(objB, A) // true

class C {}
instanceOfClass(objB, C) // false

![cover](https://storage.googleapis.com/algodailyrandomassets/curriculum/frontend/interview-questions/implement-instance-of.jpg)

You can see the full challenge with visuals at this link.

Challenges • Asked over 3 years ago by Jake from AlgoDaily

Jake from AlgoDaily Commented on Jun 04, 2022:

This is the main discussion thread generated for Implement Instance Of (Main Thread).