【发布时间】:2014-05-24 20:02:17
【问题描述】:
从CoffeeScript Ristretto看以下内容:
QueueMaker = ->
do (queue = undefined) ->
array: []
head: 0
tail: -1
pushTail: (value) ->
queue.array[tail += 1] = value
pullHead: ->
unless queue.isEmpty()
do (value = queue.array[queue.head]) ->
queue.array[queue.head] = undefined
queue.head += 1
value
isEmpty: ->
queue.tail < queue.head
可以改变queue.head - http://jsfiddle.net/VQLNG/。
queue = QueueMaker()
queue.head = 666
console.log queue
如何编写上述函数,使head 不公开?
【问题讨论】:
-
你离开了` queue = ` 行。
标签: coffeescript information-hiding