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

m
(Pascal entry)
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 46.x:
<syntaxhighlight lang="elena">import extensions;
 
class Extender : BaseExtender
{
prop object foo : prop;
constructor(object)
{
this theObjectobject := object
}
}
 
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>
{{out}}
11

edits