I've got some CoffeeScript classes which I use and extend in my code. How can I use angularjs to not have to create the usual module cruft like
MyNamespace = MyNamespace || {}
MyNamespace.SuperClass = class
and in a different file
MyNamespace = MyNamespace || {}
class ChildClass extends MyNamespace.SuperClass
MyNamespace.ChildClass = ChildClass
Could I simply write
angular('MyModule').factory, 'SuperClass', () ->
class SuperClass
constructor: (@id) ->
return SuperClass
and extend from that class via
angular('MyModule').factory, 'ChildClass', ['SuperClass', (SuperClass) ->
class ChildClass extends SuperClass
constructor: (id) ->
super(id)
return ChildClass
]
My problem is actually that Im using CoffeeScript to compile all objects into a single file. Now if a childclass is above the baseclass, the baseclass will be undefined and I'll get an error. I'm looking for an elegant and easy way how to solve this.
With Angular you can do away with putting your classes in namespaces, since the name of your module / service can be qualified and effectively serve the same purpose.
What I don't think Angular will help with is ensuring that your super class code is run before your child class code. For that there seems to be about 8000 ways of solving the problem and none of them standard - requireJs, coffeetoaster, brunch, grunt, cake.....
I use grunt, and specify the order in which I want to concat my coffeescript.
If you use Angular's DI system, it should ensure that your classes are instantiated in the correct order, regardless of which is loaded first. Is there actually an issue with your example?