
Proto Inheritance
foreach loop normally iterates over each slot in a frame. In some cases, however, you may want to iterate over not only a frame's slots, but the slots that the frame inherits, as well. The deeply version of foreach does exactly that. It iterates over each slot, including inherited slots, but skips the _proto slot. Here is an example that shows the difference:
foo := {a: 3, b: 6};
bar := {_proto: foo, a: 5};
foreach name, value deeply in bar do begin
Write(name & ": ");
Print(value);
end;
a: 5 a: 3 b: 6 foreach name, value in bar do begin Write(name & ": "); Print(value); end;
_proto: {
a: 3,
b: 6}
a: 5
An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.
Last modified: 1 DEC 1996