class Tribble
constructor:->
@isAlive=true
Tribble.count++
#Prototype properties
breed:->new Tribble if @isAlive
die:->
Tribble.count-- if @isAlive
@isAlive=false
#Class-level properties
@count:0
@makeTrouble:->console.log('Trouble!' for i in [0..@count]).join(' ')//here! here!
tribble1=new Tribble
tribble2=new Tribble
Tribble.makeTrouble()
//here! here! 行使用的列表解析最后返回的是个数组 [ 'Trouble!', 'Trouble!', 'Trouble!' ] 然后我们将数组进行 join(' ') 操作 期望的结果是 Trouble!, Trouble!, Trouble!,但是加上.join(' ') 后程序会报错如下
[ 'Trouble!', 'Trouble!', 'Trouble!' ]
TypeError: Cannot call method 'join' of undefined
at Function.Tribble.makeTrouble (C:\odd.coffee:14:19, <js>:38:13)
at C:\odd.coffee:18:4, <js>:45:13
at Object.<anonymous> (C:\odd.coffee:1:1, <js>:49:5)
at Object.<anonymous> (C:\odd.coffee:51:4)
at Module._compile (module.js:456:26)
有前辈看这本书的时候遇到同样的问题吗