Add a variable to a class instance at runtime: Difference between revisions

Line 1,065:
=={{header|Smalltalk}}==
the following addSlot function creates an anonymus class with the additional slot, defines accessor methods and clones a new instance from the given object which becomes the old one.
This preserves object identity. (by the way: if we remember and reuse these temp classes, we get the core of Google's fast JavaScript interpreter implementation ;-)
{{works with|Smalltalk/X}}
<lang smalltalk>|addSlot p|
Anonymous user