2016-06-28 12 views
1

クラスのメンバメソッド内の現在のオブジェクトを参照することは可能ですか? $childWidget SetParent $self$selfの等価何ができるかItclのクラスメソッド内の自己参照

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 
    } 
} 

: 親切に以下のコードを考えてみ?

答えて

2

もう少しオンライン検索の後に明らかになるので、 - >$this変数は、そのトリックを行う必要があります。

+0

これは答えです:itclはメソッド本体の内部に表示されている 'this'という名前の変数にある現在のオブジェクトへの参照を提供します。 –