I have a library-provided function that runs a callback after some processing.
Inside that callback, I’d like to access the parent object whose method starts that callback – see below.
class MaskMaker
addMaskedImage: (imagefile, texturefile, canvasid) ->
$('<img src="'+imagefile+'">').load ->
console.log('Id like to call another MaskMaker method with @width as a parameter')
Obviously => will give me access to the parent object as this/@, -> will give me access to the element triggering the callback as this/@. But what’s the neatest way to do both, eg, so I could call a direct method of MaskMaker with the images width as a parameter? Do I need a that = this hack or is there something better?
Thanks!
You can’t choose both (obviously), so would have to go with either
=>+event.targetor good ol’
See also: https://github.com/jashkenas/coffee-script/issues/1230