Skip to content

Instantly share code, notes, and snippets.

@padolsey
Forked from ryanflorence/_sample.js
Created November 25, 2011 22:43
Show Gist options
  • Save padolsey/1394591 to your computer and use it in GitHub Desktop.
Save padolsey/1394591 to your computer and use it in GitHub Desktop.
el.addEventListener('click', function openDialog(event) {
// open the dialog
});
el.addEventListener 'click', openDialog = (event) ->
# open the dialog
# no thanks
// what the coffeescript becomes
var openDialog;
el.addEventListener('click', openDialog = function(event) {
// open the dialog
});
// what the coffeescript COULD become
// Using solution described here: http://kangax.github.com/nfe/#jscript-memory-management
// If the intention is to have a named-func-expression (just for debugging, not referenc'able by name):
el.addEventListener('click',
(function(){
var openDialog, f = function openDialog(event) {
// open the dialog
};
openDialog = null; // null so that openDialog does not reference extraneous func
return f;
}())
);
// If the intention is to have the same BUT referenc'able by name:
var openDialog;
el.addEventListener('click',
openDialog = (function(){
var openDialog, f = function openDialog(event) {
// open the dialog
};
openDialog = null; // null so that openDialog does not reference extraneous func
return f;
}())
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment