I'm trying to pass parameters to the iterator function that the async node module requires.
async.forEach dbReply, mediaHandler(entry, event.folder, callback), (error) ->
console.log error
mediaHandler = (entry, folder, callback) ->
console.log arguments
I constantly get ReferenceError: entry is not defined
Any clue on how can I pass the event.folder parameter to the function?
Sounds like you want your mediaHandler function to return an iterator function:
mediaHandler = (folder, callback) ->
(entry) ->
# Do things with folder, callback, and entry.
# folder and callback are available through the closure,
# entry is supplied by forEach.
and then:
async.forEach dbReply, mediaHandler(event.folder, callback), (error) -> ...
Your entry argument is supplied by forEach when it calls the iterator but the other two arguments are (presumably) available when you're calling async.forEach so you're trying to curry a three argument mediaHandler to get a one argument function that forEach can deal with; there are other ways to do that in (Coffee|Java)Script but doing it by hand with a closure is probably the simplest.