Add a variable to a class instance at runtime: Difference between revisions
Content added Content deleted
No edit summary |
m (→{{header|Tcl}}: condense the requirements) |
||
Line 580: | Line 580: | ||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
{{works with|Tcl|8.6}} |
{{works with|Tcl|8.6}} or {{libheader|TclOO}} |
||
<br> |
|||
{{works with|Tcl|8.5}} and the [http://wiki.tcl.tk/TclOO TclOO package] |
|||
The code below uses the fact that each object is implemented as a namespace, to add a ''time'' variable to an instance of ''summation'': |
The code below uses the fact that each object is implemented as a namespace, to add a ''time'' variable to an instance of ''summation'': |
||
<lang Tcl>% |
<lang Tcl>% package require TclOO |
||
% oo::class create summation { |
|||
constructor {} { |
constructor {} { |
||
variable v 0 |
variable v 0 |