i have
class Main
test:->
alert "yay!"
in coffeescript, and i want to run that inside my index.html
<script>
$(function(){
//and obv Main.test(); doesn't work
});
</script>
there is a note of this on the website, it says it wouldn't work. But I couldn't find how to make it work. any ideas? i need to find out what coffeescript closure wrapper is.
or does coffeescript execute after document.ready anyway?
thx!
To execute Coffeescript after document.ready you can use jQuery like this:
$ ->
# Put your function code here
init()
What that is doing is running jQuery(function () { callback... }) like the 3rd section at this link: http://api.jquery.com/jQuery/
Which basically says this:
jQuery( callback ) Returns: jQuery Description: Binds a function to be executed when the DOM has finished loading.
I declare all my classes, etc outside of document ready and then call an init function to get it running at the appropriate time.
I hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With