The Immediately-Invoked Function Expression (IIFE) pattern could be used to
create private classes.
some.package.SomeClass = (function()
{
var SomeHelperClass = function(){};
var SomeClass = function(){};
return SomeClass;
})();
SomeHelperClass will only be accessible inside the (function(){}).
SomeClass will be returned to allow it to be exposed externally. It's a
pretty common pattern in JavaScript to avoid polluting the global namespace.
- Josh
On Mon, Nov 16, 2015 at 8:28 AM, Alex Harui <[email protected]> wrote:
>
>
> On 11/16/15, 2:38 AM, "Michael Schmalle" <[email protected]>
> wrote:
>
> >It's important. You need to figure out how to do it in JS first, then bend
> >the compiler to your will. :)
> >
> >In a SWF decompile, these are labeled private class.
>
> OK. Well AFAIK, there is no such thing as private classes in JS. One
> thought I had was to implement them as “inner classes” in JS.
>
> So the output for:
>
> >>
> >> package some.package
> >> {
> >> public class SomeClass
> >> {
> >> }
> >> }
> >>
> >> class SomeHelperClass
> >> {
> >> }
>
> would be:
>
> some.package.SomeClass = function() {}
>
> some.package.SomeClass.SomeHelperClass = function() {}
>
> Thoughts?
> -Alex
>
>