I’m a bit confused about the example on page 44 concerning @/this in a global context.
The book has this:
setName 'Lulu' console.log name # 'Lulu' console.log @name # undefined
But I can’t reproduce that (node 0.4.8, coffeescript 1.1.1)
coffee> setName = (name) -> @name = name [Function] coffee> setName 'Lulu' 'Lulu' coffee> console.log name ReferenceError: name is not defined at repl:2:1 at Object.eval (/Users/telemachus/local/node-v0.4.8/lib/node_modules/coffee-script/lib/coffee-script.js:89:15) at Interface.<anonymous> (/Users/telemachus/local/node-v0.4.8/lib/node_modules/coffee-script/lib/repl.js:39:28) at Interface.emit (events.js:64:17) at Interface._onLine (readline.js:153:10) at Interface._line (readline.js:408:8) at Interface._ttyWrite (readline.js:585:14) at ReadStream.<anonymous> (readline.js:73:12) at ReadStream.emit (events.js:81:20) at ReadStream._emitKey (tty_posix.js:307:10) coffee> console.log(@name) undefined
Edit apologies - I see that the problem appears only in coffee’s repl. If I run the code from a file, all is fine. Presumably the repl lacks a global object (or doesn’t do any assignments in a global context?) Still it might be worth mentioning or clarifying for people who run some of the code in the repl as they read (which I’ve been doing).