Hi everyone: I am trying to create a namespace so I can use a class in different coffeescript files throughout my application (at least that is my understanding of what you use a namespace for)
I found a very good example here: Classes within Coffeescript 'Namespace'
excerpt:
namespace "Project.Something", (exports) ->
exports.MyFirstClass = MyFirstClass
exports.MySecondClass = MySecondClass
However, when I implement this, I am getting: namespace is not defined in my console.
My namespace is implemented exactly how it looks in the example above. It seems that my namespace definition is just not being recognized by coffeescript somehow.
any ideas? could there be a versioning issue here or something?
thanks in advance!!!
The
namespacefunction from that question:isn’t part of CoffeeScript, you have to define that helper yourself. Presumably you don’t want to repeat it in every file so you’d have a
namespace.coffeefile (orutil.coffeeor …) that contains thenamespacedefinition. But then you’re left with the problem of getting yournamespacefunction into the global namespace. You could do it by hand:Demo: http://jsfiddle.net/ambiguous/Uv646/
Or you could get funky and use
namespaceto put itself into the global scope:Demo: http://jsfiddle.net/ambiguous/3dkXa/
Once you’ve done one of those, your
namespacefunction should be available everywhere.