Is there an easy way to do this in Smalltalk? I'm 80% sure that there is some method but can't find it anywhere.
I know that I can use
(instance class = SomeClass) ifTrue:
And I know that I can use superclass
etc... but I hope that there is something built in :)
The isinstance() method checks whether an object is an instance of a class whereas issubclass() method asks whether one class is a subclass of another class (or other classes).
Python issubclass() is built-in function used to check if a class is a subclass of another class or not. This function returns True if the given class is the subclass of given class else it returns False . Return Type: True if object is subclass of a class, or any element of the tuple, otherwise False.
Python isinstance() Function The isinstance() function returns True if the specified object is of the specified type, otherwise False .
Use the instanceof operator to check if an object is an instance of a class, e.g. if (myObj instanceof MyClass) {} . The instanceof operator checks if the prototype property of the constructor appears in the prototype chain of the object and returns true if it does. Copied!
To test whether anObject is instance of aClass:
(anObject isMemberOf: aClass)
To test whether it is an instance of aClass or one of it subclasses:
(anObject isKindOf: aClass)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With