|
|
|
|
|
by amadiver
5636 days ago
|
|
`Bind` with named methods goes a long way to cleaning up nested callbacks. Here's a (quick+dirty; I know I'm missing some `do`'s in there) version of the same code in CoffeeScript: _ =
fileMenu: ->
mainWindow.menu "File", (e,f) => this.onFile(e,f)
onFile: (err,file) ->
if err then throw err
file.openMenu (e,m) => this.onOpenMenu(e,m)
onOpenMenu: (err,menu) ->
if err then throw err
menu.item "Open", (e,i) => this.onOpen(e,i)
onOpen: (err,item) ->
if err then throw err
mainWindow.getChild type('Window'), (e,d) => this.onDialog(e,d)
onDialog: (err,dialog) ->
if err then throw err
#...
_.fileMenu()
( `=>` is CoffeeScript for a function bound to the current scope ) |
|