Instantly share code, notes, and snippets.

Embed
What would you like to do?
Design Patterns : Singleton Pattern
/**
* @fileoverview The base initialization method
* @author hwclass
*/
/**
* base.js
* This file is used to make some creating initialization routines
*/
'use strict';
//-----------------------------------------------------------
// Public
//-----------------------------------------------------------
/** @type {Object} */
var Config = require(‘models/Config’);
/** @type {Object} */
var configInstance = new Config();
/** @type {Object} */
var config = configInstance.getConfig();
/** @type {null} */
configInstance = null;
$(‘.error).html(config.messages.errors.default);
/**
* @fileoverview The base object to get configuration
* @author hwclass
*/
/**
* models/Config.js
* This object is used to fetch needed configuration parameters
*/
'use strict';
//-----------------------------------------------------------
// Public
//-----------------------------------------------------------
/**
* Config object
* @noparam
*/
module.exports = (function () {
return function () {
var config = {
urls : {
tabs : {
address : '/#address',
payment : '/#payment'
}
},
messages : {
errors : {
no_address_selected : 'Please, select an address to go next',
no_cards_used : 'You need to choose a credit card to pay',
default : 'An error occured. Please try again later'
}
}
/**
* getConfig method
* @noparam
*/
var getConfig = function () {
return config;
}
return {
getConfig : getConfig
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment