Tcl destory 得一些心得

# .tcl  可以運行

Class Bagel

Bagel instproc destory {} {   

#如果改爲porc 則下邊的abagel 的$self next不會調用次函數     

    puts "zap!"

    $self next

}


Bagel abagel


#    abagel instproc destory {} {

#        puts "c"

#        $self next

#    }


#    錯誤如下

#    abagel: unable to dispatch method instproc

#        while executing

#    "abagel instproc destory {} {

#        puts "c"

#        $self next

#    }"

#        (file "test2.tcl" line 16)

#爲什麼不能用instproc呢 ,因爲 proc是給Object增加函數的 不能繼承, 而instproc是給類

#定義繼承函數的


#Object abagel只能定義proc 類型的函數

abagel proc destory {} {

    puts "c"

    $self next            ;#調用父類中的同名可繼承函數

}

abagel destory

#c

#zap!


#puts 的錯誤用法


#puts abagel destory


#can not find channel named "abagel"

#    while executing

#"puts abagel destory"

#    (file "test2.tcl" line 13)


#正確用法1:這麼用也可以 輸出兩次

#puts [abagel destory]

#c

#zap!


#正確用法2:那麼 下面的也對了 輸出幾次都一個效果

#puts [puts [abagel destory]]


#c

#zap!

 

發佈了23 篇原創文章 · 獲贊 1 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章