Javascript namespace colision/destruction

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Javascript namespace colision/destruction

NekoHaxe
Hello list,

I have found a little problem when using haxe for js.
Some time ago I made a js for a page on the intranet,
a few days ago, a new functionality was neeede for such
page and another developer began working on it, using
some other haxe libs I have created since the first time
I touched that page. The resulting js will be conditionally
loaded depending on privileges.

Problem is, the new js, when loaded, erases both the
js namespace and my nlion.haxe.js namespace to start
constructing them from scratch. And since my coworker
is not including the same libs that I used on the first js
the old functionality is broken when the new js is loaded.

Nicolas, shouldn't there be a check in the js generation
so that insted of

nlion={}
nlion.haxe = {}
nlion.haxe.js = {}

checks if the namespace objects are here already and
start working and modifying them instead of creating
them from scratch, deleting access to anything
defined before in those namespaces.

I know the
suggested approach is to compile everything in the
same js, but this could be a problem also when
using some other js with same namespaces.

Maybe there could be a check at runtime to see
if the namespaces exists already and have some
predefined attribute made by haxe, something
similar to the __name__ attribute of classes
but at namespace level.

If the object is not found, create it and add the
attribute, if later another js needs to use the
same namespace It will reuse it and only add
and modify clasess. And if the namespace found
and is not from haxe throw an alert or something.

Is this doable? Or there is another reason for
this behavior?

Carlos



¡Todo sobre Amor y Sexo!
La guía completa para tu vida en Mujer de Hoy:
http://mx.mujer.yahoo.com/

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Javascript namespace colision/destruction

Nicolas Cannasse
NekoHaxe a écrit :

> Hello list,
>
> I have found a little problem when using haxe for js.
> Some time ago I made a js for a page on the intranet,
> a few days ago, a new functionality was neeede for such
> page and another developer began working on it, using
> some other haxe libs I have created since the first time
> I touched that page. The resulting js will be conditionally
> loaded depending on privileges.
>
> Problem is, the new js, when loaded, erases both the
> js namespace and my nlion.haxe.js namespace to start
> constructing them from scratch. And since my coworker
> is not including the same libs that I used on the first js
> the old functionality is broken when the new js is loaded.
>
> Nicolas, shouldn't there be a check in the js generation
> so that insted of
>
> nlion={}
> nlion.haxe = {}
> nlion.haxe.js = {}
>
> checks if the namespace objects are here already and
> start working and modifying them instead of creating
> them from scratch, deleting access to anything
> defined before in those namespaces.

You can now use -D check-js-packages to do that.

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org