CoffeeScript Revealing Module Pattern
by ctoestreich
HTML
<script src="http://codemirror.net/lib/codemirror.js"></script>
<link rel="stylesheet" href="http://codemirror.net/lib/codemirror.css">
<script src="http://codemirror.net/mode/javascript/javascript.js"></script>
<script type="text/javascript">$.get('http://fiddle.jshell.net/bh88/SKMpV/show/',function(){$('#code').val(CoffeeScript.compile($('script[type*=coffeescript]').html()));var editor=CodeMirror.fromTextArea(document.getElementById('code'),{lineNumbers:1,matchBrackets:1,mode:'javascript'});});</script><textarea id="code"></textarea>
CSS
/* here's that gist btw https://gist.github.com/1293230 */
#code {
display: none;
}
.CodeMirror-scroll {
height: 100% !important;
}
CoffeeScript
### See jsfiddle http://jsfiddle.net/ctoestreich/nqmjA/ ###
modulename = ((document, $) ->
privateVariable = "i am private"
# a function named doWork that returns a string 'hiho hiho'
doWork = () ->
"hiho hiho"
# a function with a explicit return with no value will remove the implied return from js
nothingToReturn = (message) ->
console.log message
return
exposeSomething = (input) ->
input + privateVariable
# this will expose the methods
doWork: doWork
exposeSomething: exposeSomething
)(document, jQuery)