jashkenas/coffee-script — Issue #1783: Reference error of a variable whithin a function scope from another function scope
Author: Izikiel
Created: 2011-10-20 22:48:13+00:00
State: open

Hello, I'm getting started with CS so I'm reading SmoothCoffeeScript and doing the exercises from it.
I've encountered this small issue:

I have this function with another function inside, and according to what I have read, its valid CS:

```
extractFootnotes = (paragraphs) ->
footnotes = []
currentNote = 0
replaceFootnote = (fragment) ->
if fragment.type = "footnote"
currentNote++
footnotes.push fragment
fragment.number = currentNote
type:"reference", number: currentNote
else
fragment
forEach paragraphs, (paragraph) ->
paragraph.content = map paragraph.content, replaceFootnote

footnotes
```
But then I get this error:

```
ReferenceError: footnotes is not defined
at /Users/ezequieldariogambaccini/Documents/CoffeScript/Books/Smooth-CoffeeScript/src-no-solutions/recluse.coffee:57:5
at /Users/ezequieldariogambaccini/Documents/CoffeScript/Books/Smooth-CoffeeScript/src-no-solutions/recluse.coffee:13:16
at /Users/ezequieldariogambaccini/Documents/CoffeScript/Books/Smooth-CoffeeScript/src-no-solutions/recluse.coffee:97:21
at Object. (/Users/ezequieldariogambaccini/Documents/CoffeScript/Books/Smooth-CoffeeScript/src-no-solutions/recluse.coffee:123:16)
at Object. (/Users/ezequieldariogambaccini/Documents/CoffeScript/Books/Smooth-CoffeeScript/src-no-solutions/recluse.coffee:125:4)
at Module._compile (module.js:402:26)
at Object.run (/usr/local/lib/node_modules/coffee-script/lib/coffee-script.js:57:25)
at /usr/local/lib/node_modules/coffee-script/lib/command.js:147:29
at /usr/local/lib/node_modules/coffee-script/lib/command.js:115:26
at [object Object]. (fs.js:107:5)
```

I think it is a matter of scope, but I thought that footnote would behave like a global to replaceFootnote.