viverosm
11 years agoNew Contributor
instance of operator for different Checkpoint types
Hello,
I have an array of objects used in checkpoints and wanted to iterate over it and do different things based on the type of object (if it's a Table, do A, if it's a Region, do B). I am using JavaScript and I tried the code below but I got an error saying Table is undefined. Is there another way to use the instance of operator to distinguish between Region objects and Table objects:
for (i = 3; i < checks.length; i++) {
I have an array of objects used in checkpoints and wanted to iterate over it and do different things based on the type of object (if it's a Table, do A, if it's a Region, do B). I am using JavaScript and I tried the code below but I got an error saying Table is undefined. Is there another way to use the instance of operator to distinguish between Region objects and Table objects:
for (i = 3; i < checks.length; i++) {
if (checks instanceof Table) {
... A ...
} else {
... B ...
}
- Hi Michael, as per the documentation here, instanceof is a native JScript operator that tests whether an object has in its prototype chain the prototype property of a constructor.
Therefore, it will only work if the Table and Region Objects are native JScript Objects, which I would doubt.
Also, how are you able to get an Array of Table and Region checkpoints, I could not find any way to achieve this.
It may be that the error saying Table is undefined is being raised as Table does not exist as an Object.
Regards,
Phil Baird