11

I start like I usually do in javascript, so:

$(document).ready ->

but when I save I get a document is not defined. So far I haven't been able to find how to make it work.

Edit: by save, I meant I was using coffee -w. The error was due to me forgetting to use the -c option.

3
  • 4
    You are compiling the CoffeeScript to JavaScript, right? Commented Feb 2, 2011 at 21:47
  • 2
    actually, that was the mistake. I added the -c to the commandline and it worked. Commented Feb 4, 2011 at 13:11
  • 16
    sidenote: you can collapse that statement into $ -> Commented Feb 6, 2011 at 5:35

1 Answer 1

18

CoffeeScript is compiled into JavaScript. I'm not sure what you're trying, but in your exact case your CoffeeScript isn't going to look a whole lot different than your JavaScript. Try:

$(document).ready -> alert 'blah'

If that doesn't work, just do a test like

alert document.title

if that doesn't work, I'm going to suggest that you're not running this code inside a browser ;)

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for this, it allowed me to see where I was wrong and it's pretty stupid. Apparently, I wasn't trying to actually compile the code, just to run it, since I had forgot to throw in the -c option, now everything is working :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.