When I pass an anonymous function with fat arrows as a socket.io callback and then call another method in the same object (as follows) the scope of @
is correct:
module.exports = class InviteCreateSocket extends AbstractSocket
register: () ->
@socket.on 'invite:create', (data, callback) => @create data, callback
create: (data = {}, callback = @_noop) ->
# This returns an instantiated InviteCreateSocket. Bonzer!
console.log @
However, if I pass it in directly, the scope is now of the socket, as if I had run the previous code with thin arrows:
module.exports = class InviteCreateSocket extends AbstractSocket
register: () ->
@socket.on 'invite:create', @create
create: (data = {}, callback = @_noop) ->
# This returns the socket. Not bonzer. Not bonzer at all.
console.log @
So, is there a nice clean way of getting object scope without having to relay them through a fat anonymous function? The first method works but seems a bit clumsy and obviously requires having to synchronise the parameters in all the methods. Thanks in advance!