# .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!