Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                /**
 * @returns {string|Readonly<{readonly, nilUUID: Object.nilUUID, generateUUID: (function(*=): string)}>}
 * @constructor
 */
const MyClass2 = function()
{
    /** @type {array} */
    const AVAILABLE_CHARACTERS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');

    /** @type {array} */
    const uuidTemplate = 'xxxxxxxx-xxxx-!xxx-?xxx-xxxxxxxxxxxx'.split('');

    /** @type {string} */
    const uuidVersion = '4';

    /**
     * @returns {string}
     */
    const getNilUUID = function()
    {
        return '00000000-0000-0000-0000-000000000000';
    };

    /**
     * Collection of public properties.
     *
     * @type {Object}
     */
    const properties = {
        nilUUID: getNilUUID(),
    };

    /**
     * Collection of public methods including setters and getters for public properties.
     *
     * @type { {readonly nilUUID: Object.nilUUID, generateUUID: (function(*=): string)} }
     */
    const methods = {
        set nilUUID(newValue) {
            if (typeof newValue !== 'string') {
                throw new TypeError('nilUUID must store string value, ' + (typeof newValue) + ' given.');
            }

            properties.nilUUID = newValue;
        },

        get nilUUID() {
            return properties.nilUUID;
        },

        /**
         * Generate and return a valid UUID
         * @see https://en.wikipedia.org/wiki/Universally_unique_identifier
         *
         * @returns {string}
         */
        generateUUID: function(isNilUUID = false)
        {
            if (isNilUUID) {
                return this.nilUUID;
            }

            let uuidVariant, i, random;
            const uuid = [];

            for (i = 0; i < uuidTemplate.length; i++) {
                random = 0 | Math.random() * 16;
                uuidVariant = (random & 0x3)  | 0x8;

                uuid[i] = uuidTemplate[i]
                    .replace(/[^\-\!\?]/, AVAILABLE_CHARACTERS[random])
                    // ! is the uuid version
                    .replace('!', uuidVersion)
                    // ? is the high bits of clock sequence according to rfc4122
                    .replace('?', AVAILABLE_CHARACTERS[uuidVariant]);
            }
            return uuid.join('');
        }
    };

    return Object.freeze(methods);
};

window['MyClass2'] = MyClass2;

const myObj2 = new MyClass2();

// Try to access private property
console.log('get private property "AVAILABLE_CHARACTERS"', myObj2.AVAILABLE_CHARACTERS);

console.info('call private method "getNilUUID()" ->');
try {
  myObj2.getNilUUID();
} catch(e) {
  console.log('Error:', e.message);
}

// Get and set public property
console.log('get public property nilUUID', myObj2.nilUUID); // '00000000-0000-0000-0000-000000000000'
console.log('call public method generateUUID(true) ->', myObj2.generateUUID(true)); // '00000000-0000-0000-0000-000000000000'
console.log('call public method generateUUID() ->', myObj2.generateUUID());
console.log('call public method generateUUID() ->', myObj2.generateUUID());

console.info('change public property nilUUID to string "Hello World!"');
myObj2.nilUUID = 'Hello World!';
console.log('get public property nilUUID', myObj2.nilUUID); // 'Hello World!'
console.log('call public method generateUUID(true) ->', myObj2.generateUUID(true)); // 'Hello World!'
console.log('call public method generateUUID() ->', myObj2.generateUUID());
console.log('call public method generateUUID() ->', myObj2.generateUUID());

// AND!
console.info('Change public method generateUUID to string "I am so sorry"');
myObj2.generateUUID = 'I am so sorry';
console.log('call public method generateUUID(true) ->', myObj2.generateUUID(true)); // 'Hello World!'
console.log('get type of public method generateUUID', typeof myObj2.generateUUID); // 'function()...'
console.log('call public method generateUUID() ->', myObj2.generateUUID());
console.log('call public method generateUUID() ->', myObj2.generateUUID());

// Add extra properties to the object
console.info('add new public property "id" with value "123"');
myObj2.id = 123;
console.log('get public property id', myObj2.id);
              
            
!
999px

Console