Search code examples
tclitcl

Self refence within class methods in Itcl


Is it possible to refer to current object within the member method of a class. Kindly consider the code below:

itcl::class widget {
   private variable inst

   method ChildCount {} {
       return [llength [keylkeys inst children]]
   }
   method AddChild {childWidget} {
       inst children.[ChildCount] $childWidget
       # ***HOW TO GET THIS WORKING?***
       $childWidget SetParent $self
   }
}

What could be the equivalent for $self in $childWidget SetParent $self?


Solution

  • Ok, so evident after little more online search -> $this variable should do the the trick.