Namespace by direct assignment
suggest change//Before: antipattern 3 global variables
var setActivePage = function () {};
var getPage = function() {};
var redirectPage = function() {};
//After: just 1 global variable, no function collision and more meaningful function names
var NavigationNs = NavigationNs || {};
NavigationNs.active = function() {}
NavigationNs.pagination = function() {}
NavigationNs.redirection = function() {}
var at the top of a classic script creates a global, and the declaration is hoisted, so the first NavigationNs || {} sees undefined. A module does not create that global; export the object instead.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents