Type () can be used to distinguish obj-map_arr, but I don't know how to classify some special objects, such as class. Does the class object have any characteristics that can be used to judge?
for i,n in type(t)="object"?t.OwnProps():t
The current solution is to create a list of all possible occurrence types, and if it is not in the list, it is a class.
How to distinguish between many types of object?
Re: How to distinguish between many types of object?
Code: Select all
Class test{
}
MsgBox Type(test) ;Class
MsgBox test.prototype.__Class ;test
Re: How to distinguish between many types of object?
such?
Code: Select all
Class test{
}
t:=test.new()
MsgBox Type(t) ;Class
MsgBox t.prototype.__Class ;test
Re: How to distinguish between many types of object?
Code: Select all
Class test{
}
t:=test.new()
MsgBox t.base.base.__Class ;Object
MsgBox Type(t) ;test
Re: How to distinguish between many types of object?
Code: Select all
MsgBox [].base.base.__Class ;Object
In fact, there is only one place I need to judge its exact type:
for k,v in obj ;--->> obj? or obj.OwnProps()?
Re: How to distinguish between many types of object?
Probably:
EDIT: fixed code
Code: Select all
Class test{
}
t:=test.new()
t.1:=1
t.a:=2
for k, v in (t.hasMethod("__Enum")?t:t.OwnProps())
MsgBox k "`n" v
Re: How to distinguish between many types of object?
Actualy it is easier to add __Enum to object class:
Code: Select all
Class test{
__Enum(*) => this.OwnProps()
}
t:=test.new()
t.1:=1
t.a:=2
for k, v in t
MsgBox k "`n" v
Re: How to distinguish between many types of object?
Thank you. We should consider that the source of many classes is unknown.
Re: How to distinguish between many types of object?
Struct does not have hasMethod, hasMethod("__Enum ") does not seem to be the perfect solution.
Re: How to distinguish between many types of object?
I have added HasMethod to Struct.
Note that not all objects (COM) will support __Enum/for loop.
Note that not all objects (COM) will support __Enum/for loop.
Re: How to distinguish between many types of object?
Last edited by Helgef on 07 Mar 2020, 13:00, edited 1 time in total.
Re: How to distinguish between many types of object?
It does not help judge the two:
obj.__Enum or obj.OwnProps()
obj.__Enum or obj.OwnProps()
Who is online
Users browsing this forum: No registered users and 24 guests