Return to Snippet

Revision: 37907
at December 20, 2010 08:49 by terrencewood


Updated Code
/**
 * Example singleton
 */
 
 
Singleton = (function() {
	
	return {
		
		
		/**
		 * Create a new dom node
		 *
		 * @param {String} className add a class to the node
		 * @param {String} nodeName the node to create
		 *
		 * @example
		 * <code>	
		 * 	Singleton.create('foo', 'span');
		 * </code>
		 *
		 * @return {HTML element} the new node
		 */
		
		create : function( className, nodeName ) {
			nodeName = nodeName || 'div';
			var elem = doc.createElement( nodeName );
			elem.className = className;
			return elem;
		},
		
		/**
		 * Appends a string to 'Hello '
		 *
		 * @param {String} str the string to append
		 *
		 * @example
		 * <code>
		 * 	Singleton.helloworld('world');
		 * </code>	
		 *
		 * @return {String} the modified string
		 */
		
		helloworld : function( str ) {
			output = 'Hello ' + str;
			return output;
		}
		
	}

})();

Revision: 37906
at December 20, 2010 08:49 by terrencewood


Updated Code
/**
 * Example singleton
 */
 
 
Singleton = (function() {
	
	return {
		
		
		/**
		 * Create a new dom node
		 *
		 * @param {String} className add a class to the node
		 * @param {String} nodeName the node to create
		 *
		 * @example
		 * <code>	
		 * 	Singleton.create('foo', 'span');
		 * </code>
		 *
		 * @return {HTML element} the new node
		 */
		
		create : function( className, nodeName ) {
			nodeName = nodeName || 'div';
			var elem = doc.createElement( nodeName );
			elem.className = className;
			return elem;
		},
		
		/**
		 * Appends a string to 'Hello '
		 *
		 * @param {String} str the string to append
		 *
		 * @example
		 * <code>
		 * 	Singleton.helloworld('world');
		 * </code>	
		 *
		 * @return {String} the modified string
		 */
		
		helloworld: function( str ) {
			output = 'Hello ' + str;
			return output;
		}
		
	}

})();

Revision: 37905
at December 20, 2010 08:47 by terrencewood


Initial Code
/**
 * Example singleton
 */
 
 
Singleton = (function() {
	
	return {
		
		
		/**
		 *	Create a new dom node
		 *
		 *	@param {String} className add a class to the node
		 *	@param {String} nodeName the node to create
		 *
		 *	@example
		 *	<code>	
		 *		Singleton.create('foo', 'span');
		 *	</code>
		 *
		 *	@return {HTML element} the new node
		 */	
		
		create : function( className, nodeName ) {
			nodeName = nodeName || 'div';
			var elem = doc.createElement( nodeName );
			elem.className = className;
			return elem;
		},
		
		/**
		 * Appends a string to 'Hello '
		 *
		 * @param {String} str the string to append
		 *
		 * @example
		 *	<code>
		 *		Singleton.helloworld('world');
		 *	</code>	
		 *
		 * @return {String} the modified string
		 */
		
		helloworld: function( str ) {
			output = 'Hello ' + str;
			return output;
		}
		
	}

})();

Initial URL

                                

Initial Description

                                

Initial Title
Singleton Pattern

Initial Tags
javascript

Initial Language
JavaScript