Re:[haXe] JS Isolation/Namespace

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re:[haXe] JS Isolation/Namespace

Skial Bainn

Hello,

I was actually playing with the ocaml js target yesterday, adding (function() { })(); and probably some of what the patch does.

As far as I understand the self executing function interferes with haxe remoting and possibly other features, but this can be fixed by a few ways.

(function() {

var com = com || {};

com.display = com.display || {};

com.display.Display = function() {};

var haxe = haxe || {};

...

return {

haxe:haxe,

com:com

}

})();

Or add to a passed context

(function(context){

var com = com || {};

...

context.haxe = haxe;

context.com = com;

})(window);

Both of these minimise global littering, with the js-namespace you could reduce this to 1;

(function(){

..

return {

namespace {


haxe:haxe,


com:com


}


}

})();

(function(context){

...

context.namespace.haxe = haxe;

context.namespace.com = com;

})(window);

I think the context version will cause problems when the context isn't set as window. Correct me if I'm wrong on any of the above. Someone with better js knowledge might be able to offer a better suggestion.

I wont be able to reply to anyone until later today.

Also I apologise if the formatting is crap, im typing on my tablet.

On Oct 14, 2011 10:49 PM, "Nicolas Cannasse" <[hidden email]> wrote:
Hi list,

I'm thinking about removing --js-namespace and replacing with with another flag that will ensure that the JS code does not pollute the global namespace.

First step has been done by integrating Philippe patch which adds "var" everywhere needed, the isolation flag will simply add the following code around the generated JS :

(function(){ .... })();

This will be the default behavior in order to keep backward compatibility.

Now what about the flag name, it should be --js-something, any idea ?

Best,
Nicolas

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

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