I cam upon this code in an example for the EaselJS library - what it does is it assigns the namespace of the entire createjs library to "window".
<script>
var createjs = window;
</script>
My question is this: Is setting the namespace of a library to window a really dumb idea? Doesn't it just get rid of the whole point of using a namespace by making all the namespaced variable suddenly global scoped?
The only advantage I can see is letting you write shorter contructors for your objects. For example typing:
stage = new Stage(canvas);
instead of:
stage = new createjs.Stage(canvas);
Is this a bad idea, or is is somehow brilliant, or just harmlessly quirky?
The reason this was set up this way was to maintain backwards-compatibility with previous versions which were not namespaced. This allows developers to upgrade to the latest version when it was added without having to refactor all their code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With