/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * 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; } } })();