Add a variable to a class instance at runtime: Difference between revisions
Content added Content deleted
Line 326: | Line 326: | ||
=={{header|Elena}}== |
=={{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 does not support adding a field at run-time but it can be simulated with the help of a mix-in. |
||
ELENA 3. |
ELENA 3.2: |
||
<lang elena>import extensions. |
<lang elena>import extensions. |
||
class Extender :: BaseExtender |
class Extender :: BaseExtender |
||
{ |
{ |
||
object foo :: |
object prop foo :: theField. |
||
constructor new : anObject |
constructor new : anObject |
||
Line 344: | Line 345: | ||
// extending an object with a field |
// extending an object with a field |
||
anObject := Extender new |
anObject := Extender new(anObject). |
||
anObject foo := "bar". |
anObject foo := "bar". |
||
console printLine |
console printLine(anObject,".foo=",anObject foo). |
||
console readChar. |
console readChar. |