Created
December 16, 2011 19:17
-
-
Save gonzedge/1487491 to your computer and use it in GitHub Desktop.
CoffeeScript: The '=>' operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
outerFunctionWithCallback = (options, callback) -> | |
# Do something with options | |
callback() | |
theFunction = -> | |
self = @ | |
@doFirstThing = -> # ... | |
@doSecondThing = -> # ... | |
initialize = -> | |
self.doFirstThing(); | |
self.doSecondThing(); | |
outerFunctionWithCallback {}, initialize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var outerFunctionWithCallback = function(options, callback) { | |
/* Do something with options */ | |
callback(); | |
}; | |
var theFunction = function(){ | |
var self = this; | |
this.doFirstThing = function() { /* ... */ }; | |
this.doSecondThing = function() { /* ... */ }; | |
var initialize = function() { | |
self.doFirstThing(); | |
self.doSecondThing(); | |
}; | |
outerFunctionWithCallback({/* options */}, initialize); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
outerFunctionWithCallback = (options, callback) -> | |
# Do something with options | |
callback() | |
theFunction = -> | |
@doFirstThing = -> # ... | |
@doSecondThing = -> # ... | |
initialize = => | |
@doFirstThing(); | |
@doSecondThing(); | |
outerFunctionWithCallback {}, initialize; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment