Best approach avoid naming conflicts for javascript functions in separate .js files?

javascript

Solution

I limit the scope of the function to that file.

(function () {
    var AddTag = function AddTag () {
    };
}());

… and sometimes make some functions in it available to the global scope:

var thisNamespace = function () {
    var AddTag = function AddTag () {
        …
    };
    var foo = function foo() {
        AddTag();
        …
    };
    var bar = function bar() {
        …
    };
    return {
        foo: foo,
        bar: bar
    }
}();

Problem

Is there a preferred approach to isolating functions in a .js file from potential conflicts with other .js files on a page due to similar names? For example if you have a function ``` function AddTag(){} ``` in Core.js and then there is a ``` function AddTag(){} ``` in Orders.js they would conflict. How would you best structure your .js files and what naming conventions would you use to isolate them? Thanks

Original source