For some reason, my classes written in CoffeeScript do not copy the prototype.
Here's the exact code I'm using:
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
This is the prototype of the class, as expected:
{ add: [Function],
shift: [Function],
queueIndex: [Function],
get: [Function],
length: [Function],
remove: [Function] }
But this is weird: new ListQueue
actually gives me this:
{ queue: [], queueIds: [], currentId: 0 }
I'm using Node.JS 0.8.7.
The do function is actually there, if you execute
new Test().do()
you will get "test"
If you want intellisense type support, try adding a constructor first. It will create function variables, and bind them, like so:
this.LoadData = __bind(this.LoadData, this);
This will allow you to explicitly call them.