globals!

41 views
Skip to first unread message

Brian Craft

unread,
May 23, 2013, 12:59:12 PM5/23/13
to fla...@googlegroups.com
Why does flapjax export all of its methods as globals? All of the this.<blah> assignments at the bottom of the source are assigning to the global object.

Predictably, this breaks things.

Jay Shepherd

unread,
May 23, 2013, 5:38:47 PM5/23/13
to fla...@googlegroups.com
I found this version of flapjax somewhere that has been scoped for Google Closure. You may find it useful. 
There are a few modifications of my own, but nothing major.




On Fri, May 24, 2013 at 4:59 AM, Brian Craft <craft...@gmail.com> wrote:
Why does flapjax export all of its methods as globals? All of the this.<blah> assignments at the bottom of the source are assigning to the global object.

Predictably, this breaks things.

--
--
Flapjax home page: www.flapjax-lang.org
Flapjax list: groups.google.com/group/flapjax
Post: fla...@googlegroups.com
Unsubscribe: flapjax-u...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Flapjax" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flapjax+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Brian Craft

unread,
May 23, 2013, 6:20:36 PM5/23/13
to fla...@googlegroups.com
Sorry, I'm not following. It looks like closure is the problem: it's generating these dozens of globals. How is this version different? Is it the "flapjax = F"? 

Jay Shepherd

unread,
May 23, 2013, 9:42:53 PM5/23/13
to fla...@googlegroups.com
Maybe i dont understand your problem. 
This version is different because everything is scoped to the F object and the only global is F.
If your not using closure compiler you will need to get rid of lines 36 and 37

var gProvide = goog['provide'];
gProvide('F');


Brian Craft

unread,
May 24, 2013, 12:15:28 AM5/24/13
to fla...@googlegroups.com
I started with this:


which I think is the output of the compiler. At the bottom of it there are very many assignments to the global object, like so:

this.TEXT = impl.TEXT;
this.fold = impl.fold;
this.foldR = impl.foldR;
this.map = impl.map;
this.filter = impl.filter;
this.member = impl.member;
this.slice = impl.slice;
this.forEach = impl.forEach;

This is very, very, very bad.

I pulled the repo, which looks much like the file you suggested, starting with this:

goog.provide('F');

/**
 * @namespace Flapjax
 */
F = F || { };

Since it looks like your file, I expected it would compile the same way.

Jay Shepherd

unread,
May 24, 2013, 5:13:47 PM5/24/13
to fla...@googlegroups.com
Oh i see what you mean. 
These are just utility functions, they are not used internally that much. You should be able to scope them to what ever other object if you prefer. Just update the flapjax references. I think they were made global because they dont really fit in the flapjax namespace. But i agree they should be in some namespace and not global. 

Also the first versions of flapjax didn't have a namespace at all. 

Brian Craft

unread,
May 24, 2013, 6:16:57 PM5/24/13
to fla...@googlegroups.com
Are there directions anywhere for building from the source? There doesn't seem to be a top-level makefile that works. There's both a src and new-src directory, both with flapjax.js files that require compilation with closure, it appears.

Leo Meyerovich

unread,
May 24, 2013, 1:35:15 PM5/24/13
to fla...@googlegroups.com
Hi Brian,

You can avoid the issue without modifying library code:

<script>var oldWindow = window; window = {}</script>
<script src="flapjax.js"></script>
<script>var $F = window.flapjax; window = oldWindow</script>

We used to have a flag for how to export, but would never use it. If we bring it back, adopting a require.js / nodejs convention seems like the fix.

Out of curiosity, what library is this conflicting with? (Agreed that exporting FP constructs such as 'map' is in bad taste).

Regards,

- Leo









On May 23, 2013, at 9:59 AM, Brian Craft <craft...@gmail.com> wrote:

Why does flapjax export all of its methods as globals? All of the this.<blah> assignments at the bottom of the source are assigning to the global object.

Predictably, this breaks things.

Reply all
Reply to author
Forward
0 new messages