我有以下代码:
class Number
number = null
constructor: (num) ->
number = num
getNumber: -> number
class Sequence
numbers = []
constructor: ->
addNumber: (n) ->
numbers.push new Number n
displaySequence: ->
for number in numbers
alert number.getNumber()
seq = new Sequence()
seq.addNumber 1
seq.addNumber 2
seq.displaySequence()
numbers
数组seq
应该包含 2 个值为 1 和 2的Number
对象,但我得到的结果是 2 和 2 ......有人能给我一些启示吗?