Javascript 5 Module Pattern internal name
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
I'm learning about the Javascript module pattern from an array of online sources. The following suits my basic needs at the moment:
var module = function()
// Create the return module and its configuration
var module = ,
config =
css:
classes:
heading:'h1',
navbar:'nav-bar'
,
ids:
widget:'widget',
block:'block'
,
userName:'user',
token:'UUID'
;
// Private methods
function _moduleMethod()
console.log(config.userName);
// Add functionality to the module's init()-ialising method
function init()
_moduleMethod();
// Add init, and any other methods, to obj
module["init"] = init;
// Return a the module as a Public API
return module;
();
// When the DOM is ready, run the module
document.addEventListener("DOMContentLoaded", function()
module.init();
);
My question is regarding the naming of the internal return object the same as the external variable "module". My thinking is that it's OK given closure and scoping but most of the examples I've seen name the internal object something like "obj" or "my". Am I going to run into issues down the line, say with the Augmenting module pattern?
javascript revealing-module-pattern
add a comment |Â
up vote
0
down vote
favorite
I'm learning about the Javascript module pattern from an array of online sources. The following suits my basic needs at the moment:
var module = function()
// Create the return module and its configuration
var module = ,
config =
css:
classes:
heading:'h1',
navbar:'nav-bar'
,
ids:
widget:'widget',
block:'block'
,
userName:'user',
token:'UUID'
;
// Private methods
function _moduleMethod()
console.log(config.userName);
// Add functionality to the module's init()-ialising method
function init()
_moduleMethod();
// Add init, and any other methods, to obj
module["init"] = init;
// Return a the module as a Public API
return module;
();
// When the DOM is ready, run the module
document.addEventListener("DOMContentLoaded", function()
module.init();
);
My question is regarding the naming of the internal return object the same as the external variable "module". My thinking is that it's OK given closure and scoping but most of the examples I've seen name the internal object something like "obj" or "my". Am I going to run into issues down the line, say with the Augmenting module pattern?
javascript revealing-module-pattern
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm learning about the Javascript module pattern from an array of online sources. The following suits my basic needs at the moment:
var module = function()
// Create the return module and its configuration
var module = ,
config =
css:
classes:
heading:'h1',
navbar:'nav-bar'
,
ids:
widget:'widget',
block:'block'
,
userName:'user',
token:'UUID'
;
// Private methods
function _moduleMethod()
console.log(config.userName);
// Add functionality to the module's init()-ialising method
function init()
_moduleMethod();
// Add init, and any other methods, to obj
module["init"] = init;
// Return a the module as a Public API
return module;
();
// When the DOM is ready, run the module
document.addEventListener("DOMContentLoaded", function()
module.init();
);
My question is regarding the naming of the internal return object the same as the external variable "module". My thinking is that it's OK given closure and scoping but most of the examples I've seen name the internal object something like "obj" or "my". Am I going to run into issues down the line, say with the Augmenting module pattern?
javascript revealing-module-pattern
I'm learning about the Javascript module pattern from an array of online sources. The following suits my basic needs at the moment:
var module = function()
// Create the return module and its configuration
var module = ,
config =
css:
classes:
heading:'h1',
navbar:'nav-bar'
,
ids:
widget:'widget',
block:'block'
,
userName:'user',
token:'UUID'
;
// Private methods
function _moduleMethod()
console.log(config.userName);
// Add functionality to the module's init()-ialising method
function init()
_moduleMethod();
// Add init, and any other methods, to obj
module["init"] = init;
// Return a the module as a Public API
return module;
();
// When the DOM is ready, run the module
document.addEventListener("DOMContentLoaded", function()
module.init();
);
My question is regarding the naming of the internal return object the same as the external variable "module". My thinking is that it's OK given closure and scoping but most of the examples I've seen name the internal object something like "obj" or "my". Am I going to run into issues down the line, say with the Augmenting module pattern?
javascript revealing-module-pattern
asked Jan 18 at 2:59
sansSpoon
1234
1234
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
Because of the scoping inside a closure you will not run into a problem.
The Revealing Module Pattern
I want to introduce this type of module pattern because it does not need the helper object module
. Instead of collecting all public functions inside an object called module
return directly an object with all public functions. This will reduce code and result in a better to reading code.
var module = function ()
var config =
css:
classes:
heading: 'h1',
navbar: 'nav-bar'
,
ids:
widget: 'widget',
block: 'block'
,
userName: 'user',
token: 'UUID'
;
function _moduleMethod()
console.log(config.userName);
function init()
_moduleMethod();
// Return an object as public API
return
init: init
();
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Because of the scoping inside a closure you will not run into a problem.
The Revealing Module Pattern
I want to introduce this type of module pattern because it does not need the helper object module
. Instead of collecting all public functions inside an object called module
return directly an object with all public functions. This will reduce code and result in a better to reading code.
var module = function ()
var config =
css:
classes:
heading: 'h1',
navbar: 'nav-bar'
,
ids:
widget: 'widget',
block: 'block'
,
userName: 'user',
token: 'UUID'
;
function _moduleMethod()
console.log(config.userName);
function init()
_moduleMethod();
// Return an object as public API
return
init: init
();
add a comment |Â
up vote
1
down vote
Because of the scoping inside a closure you will not run into a problem.
The Revealing Module Pattern
I want to introduce this type of module pattern because it does not need the helper object module
. Instead of collecting all public functions inside an object called module
return directly an object with all public functions. This will reduce code and result in a better to reading code.
var module = function ()
var config =
css:
classes:
heading: 'h1',
navbar: 'nav-bar'
,
ids:
widget: 'widget',
block: 'block'
,
userName: 'user',
token: 'UUID'
;
function _moduleMethod()
console.log(config.userName);
function init()
_moduleMethod();
// Return an object as public API
return
init: init
();
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Because of the scoping inside a closure you will not run into a problem.
The Revealing Module Pattern
I want to introduce this type of module pattern because it does not need the helper object module
. Instead of collecting all public functions inside an object called module
return directly an object with all public functions. This will reduce code and result in a better to reading code.
var module = function ()
var config =
css:
classes:
heading: 'h1',
navbar: 'nav-bar'
,
ids:
widget: 'widget',
block: 'block'
,
userName: 'user',
token: 'UUID'
;
function _moduleMethod()
console.log(config.userName);
function init()
_moduleMethod();
// Return an object as public API
return
init: init
();
Because of the scoping inside a closure you will not run into a problem.
The Revealing Module Pattern
I want to introduce this type of module pattern because it does not need the helper object module
. Instead of collecting all public functions inside an object called module
return directly an object with all public functions. This will reduce code and result in a better to reading code.
var module = function ()
var config =
css:
classes:
heading: 'h1',
navbar: 'nav-bar'
,
ids:
widget: 'widget',
block: 'block'
,
userName: 'user',
token: 'UUID'
;
function _moduleMethod()
console.log(config.userName);
function init()
_moduleMethod();
// Return an object as public API
return
init: init
();
answered Jan 19 at 7:30
Roman
20517
20517
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f185362%2fjavascript-5-module-pattern-internal-name%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password