何らかの理由で、CoffeeScript で記述された私のクラスはプロトタイプをコピーしません。
私が使用している正確なコードは次のとおりです。
module.exports = class ListQueue
constructor: ->
@queue = []
@queueIds =[]
@currentId = 0
# Adds the given element to the queue.
# Returns the index of the element.
add: (el) ->
@queueIds.push @currentId
@queue.push el
@currentId++ # return @lastIndex, then increment
shift: ->
@queueIndexes.shift()
@queue.shift()
# Returns the index in the @queue array for the given id.
queueIndex: (id) ->
for queueIndex, i in queueIndexes
if queueIndex is id
return i
undefined
get: (id) ->
index = @queueIndex id
@queue[index]
length: ->
@queue.length
remove: (id) ->
index = @queueIndex id
if index?
@queueIds = @queueIds.slice index, index
@queue = @queue.slice index, index
true
else
false
予想どおり、これはクラスのプロトタイプです。
{ add: [Function],
shift: [Function],
queueIndex: [Function],
get: [Function],
length: [Function],
remove: [Function] }
しかし、これは奇妙です:new ListQueue
実際に私にこれを与えます:
{ queue: [], queueIds: [], currentId: 0 }
Node.JS 0.8.7 を使用しています。