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