How to create obfuscatable variables and functions in a javascript module?

I have a set of js files I concatenate into a unique file at compile time, before running YUI compressor on it (all under maven).

Unfortunately, the content of a file is not obfuscated. It is as if all declared variables and methods were considered public (and therefore not obfuscatable).

For example a.js uses methods declared in b.js. The content of the concatenated file is:

(function() {

    // b.js' content...

    // a.js' content...
    (function() {

        // Some var and methods of a declared here

        $(document).ready(function(){

            // Calls some a.js and b.js methods
            ...

        });

    })();

})();

The functions and variables of b.js are defined as following in the b.js file:

var B1 = "Some text";
var B2 = "More text";
...

function MyPrivateMethod1() { ... };
function MyPrivateMethod2() { ... };

The methods of a.js are obfuscated, but not those of b.js. I can see B1, B2, MyPrivateMethod1, MyPrivateMethod1... in the concatenated file, but I cannot find the variables and methods of a.js (the names have been obfuscated).

How can I obfuscate the var and methods of b.js in the concatenated file? (REM: I need to keep b.js as a separate file).

Answers


I found a solution, but I am not sure it is the best one. I moved b.js's code in a function:

var dummy = function() {

    var B1 = "Some text";
    var B2 = "More text";
    ...

    var MyPrivateMethod1 = function() { ... };
    var MyPrivateMethod1 = function() { ... };
    ...

    function MyPublicMethod1() { ... };
    function MyPublicMethod2() { ... };
    ...

}

Need Your Help

Firefox vs. Chrome CSS lining up issue

css cross-browser ubuntu-11.10

(see attached jsfiddle, screenshots; running browsers on Ubuntu 11.10)

Getting Resources from SherlockFragment

android actionbarsherlock android-resources

I am trying to get a color from colors.xml, using something along the lines of