jashkenas/coffee-script — Issue #2084: "class Namespace.XYZ" clobbers (locally) the global XYZ object
Author: BenjieGillam
Created: 2012-01-31 17:18:02+00:00
State: open

For example, the following CoffeeScript:

class Namespace
class Namespace.Math
@A:Math.PI

causes `Math.PI` to be read from the new (empty) constructor function, rather than the global `Math` object and thus leaves `Namespace.Math.A` as `undefined`.

A potential workaround to this would be to take the full class name `Namespace.Math` as the internal function name for the constructor (modified as needed), for example:

var Namespace;
Namespace = (function() {
function Namespace() {}
return Namespace;
})();
Namespace.Math = (function() {
function Namespace_Math() {}
Namespace_Math.A = Math.PI;
return Namespace_Math;
})();

(This solution is far from perfect - it still conflicts with any `Namespace_Math` object - but makes conflicts less likely?)