For now I'm using
export def IsInstanceOf(o: any, type: string): bool
return type(o) == v:t_object && type == typename(o)[7 : -2]
enddef
Is there something better? A planned builtin?
I don't actually need it yet, but I'm just getting started and I know how I am.
-ernie
For now I'm using export def IsInstanceOf(o: any, type: string): bool return type(o) == v:t_object && type == typename(o)[7 : -2] enddef Is there something better? A planned builtin? I don't actually need it yet, but I'm just getting started and I know how I am.Implementing "instanceof" is in the todo list. I haven't looked into the details yet. Probably similar to how Java works. Although I have always found it a bit confusing that it results in true for an object that is a child of the class being tested with.
Yeah, In Java's java.lang.Class, there's both
"isInstance(Object)" and
"isAssignableFrom(Class<?>); they both basically test
assignment compatibility,
same as the languages "instanceof" operator.
And with that reminder, I'm changing the name of my temporary helper class to
export def IsSameType(o: any, type: string): bool
since it doesn't test assignment compatibility. (And for now
don't worry about
same class name but different file.)
-ernie