Jump to content

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

Line 326:
=={{header|Elena}}==
ELENA does not support adding a field at run-time but it can be simulated with the help of a mix-in.
 
ELENA 3.12:
<lang elena>import extensions.
 
class Extender :: BaseExtender
{
object prop foo :: prop(theField).
constructor new : anObject
Line 344 ⟶ 345:
// extending an object with a field
anObject := Extender new:(anObject).
 
anObject foo := "bar".
 
console printLine:(anObject:,".foo=":(,anObject foo).
 
console readChar.
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.