The inherited Keyword

The :? Operator

In some cases, you may provide a method and not know whether a previous version exists. For example, you could very well want to use a view system method in a template without knowing whether its proto contains that method. NewtonScript provides a solution to this problem in the form of the :? operator:

inherited:?Method()
This calls the inherited version of Method only if it exists. If not, it does nothing. It is equivalent to having written:

if inherited:Method exists then
   inherited:Method();
It is quicker when an inherited version of Method exists, however, as lookup occurs once rather than twice.

If you are trying to determine whether a method exists, make sure to use frame:Method exists and not frame.Method exists (colon not period). The former uses both proto and parent inheritance (see "Combining Proto and Parent Inheritance" on page 96); the latter only uses proto inheritance.


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996