Skip to content

Instantly share code, notes, and snippets.

@JonathonMA
Created June 24, 2013 07:00
Show Gist options
  • Save JonathonMA/5848204 to your computer and use it in GitHub Desktop.
Save JonathonMA/5848204 to your computer and use it in GitHub Desktop.
Wrap coffeescript in a closure
require 'coffee-script'
code = DATA.read
magic_code = <<_EOJS_
_magic_code = ($) ->
#{code}
_magic_code(jQuery);
_EOJS_
puts CoffeeScript.compile magic_code
__END__
$ -> alert "hi from coffee script town"
@JonathonMA
Copy link
Author

(function() {
  var _magic_code;

  _magic_code = function($) {
    return $(function() {
      return alert("hi from coffee script town");
    });
  };

  _magic_code(jQuery);

}).call(this);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment