You'll "pollute the global scope" no matter how you do it. It's just a matter of how you do it.
The @
symbol in CoffeeScript is used to mean "this scope". So you can even use it on a Class definition. The result on a class declaration is that the class is defined in the scope of the window
object (unless there are some other circumstances, but that's not likely in what you're describing here).
class @CustomClassName
constructor: ->
# constructor stuff goes down...
However, I prefer to do this with a namespace, personally.
Think about google.maps.Map
or if you've ever written Actionscript 3: flash.display.MovieClip
.
At the top of your CoffeeScript file put something along the lines of this:
window.customnamespace = window.customnamespace || {}
Now when you create your class, you can say:
class customnamespace.ClassName
constructor: (container) ->
# set the container
@container = container
# etc...
class customnamespace.OtherClassName
constructor: ->
# Another class...
In your document.ready
(if you're using jQuery) you'll globally have access to that namespace and all its classes.
Example:
$(document).ready(function(e) {
var c = new customnamespace.ClassName($('#container'));
var other = new customnamespace.OtherClassName();
Make sense?