Co2 Co2 - 3 months ago 26
CoffeeScript Question

noConflict in Coffeescript?

I have the following JavaScript for a datepicker in my rails application but I want to use coffeescript and I am wondering how to implement no conflict on this function in coffeescript?

<script>
var $j = jQuery.noConflict();
$(function(){
$('#datepicker').fdatepicker({
initialDate: '02-12-1989',
format: 'dd-mm-yyyy',
disableDblClickSelection: true
});
});
</script>


Also the above works but I have to refresh the page before it does. Any advice on both? Thanks.

Answer

Here's what it might look like in CoffeeScript.

$j = jQuery.noConflict()
$ ->
  $('#datepicker').fdatepicker
    initialDate: '02-12-1989'
    format: 'dd-mm-yyyy'
    disableDblClickSelection: true
  return

When it runs in the browser it's still running as JavaScript so the functionality jQuery.noConflict() offers is still going to be there.

Comments