I have two classes, one depends on another. It is implemented like this:
class myns.ClassA
constructor(@serviceB): ->
publicFunctionA: ->
privateFunctionB.call this
privateFunctionB = ->
@serviceB.someFunction()
then I instantiate it in a glue piece:
myns.classA = new myns.ClassA(myns.serviceB)
and use as:
myns.classA.publicFunctionA()
The problem here is I want to access serviceB from privateFunctionB. Is there more appriopriate way of doing this besides using call
?
Or perhaps my entire approach is tainted too much by my Java backgound? What I need are interdependent code modules, some kind of equivalent to singleton services. I know I could use coffeescript class functions and avoid instantation but how to handle injecting serviceB in a clean way then?