Add a variable to a class instance at runtime: Difference between revisions
Content added Content deleted
(Pascal entry) |
|||
Line 340: | Line 340: | ||
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 |
ELENA 6.x: |
||
<syntaxhighlight lang="elena">import extensions; |
<syntaxhighlight lang="elena">import extensions; |
||
class Extender : BaseExtender |
class Extender : BaseExtender |
||
{ |
{ |
||
object foo : prop; |
|||
constructor(object) |
|||
{ |
|||
this object := object |
|||
} |
|||
} |
} |
||
public program() |
public program() |
||
{ |
{ |
||
var object := 234; |
|||
// extending an object with a field |
|||
object := new Extender(object); |
|||
object.foo := "bar"; |
|||
console.printLine(object,".foo=",object.foo); |
|||
console.readChar() |
|||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |