Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1488 |
|
Package | general | |
Module | images | |
Tool | regionmanager |
- if (is_defined('thing') && is_record(thing) && + has_field(thing, 'type') && is_function(thing.type) + && thing.type() == 'regionmanager') { + print 'yippee' + } else { + print 'it is a sad day that we do not have a regionmanager' + };
Imagine we have been given a Glish variable called thing in some function but we can't guarentee its a Regionmanager, as expected. To write robust code, we need to check that it is. This bit of code does that. Note the use of the short cut ``&&'' operator. A statement is only evaluated if the statement to the left is true.