Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <pre id="output"></pre>
              
            
!

CSS

              
                
              
            
!

JS

              
                // Create an instance of our cache and set some keys. Notice that the [new] operator
// is optional since the SimpleCache (and revealing module pattern) doesn't use
// prototypical inheritance. And, we can use method-chaining to set the cache keys.
var cache = SimpleCache().init();

output = document.getElementById('output')
output.innerHTML += (cache.get('a')) + '\n' + (cache.get('x'));

// ---------------------------------------------------------- //
// ---------------------------------------------------------- //

// I provide a super simple cache container.
function SimpleCache() {

    // Create an object without a prototype so that we don't run into any cache-key
    // conflicts with native Object.prototype properties.
    var cache = Object.create(null);

    var priv = {
        get: get,
        has: has,
        remove: remove,
        set: set,
        init: init,
        initSome: initSome,
        initMore: initMore
    };

    var publ = {
        get: get.bind(priv),
        has: has.bind(priv),
        remove: remove.bind(priv),
        set: set.bind(priv),
        init: init.bind(priv)
    };

    // Reveal the public API.
    return (publ);

    // ---
    // PUBLIC METHODS.
    // ---

    // I get the value cached at the given key; or, undefined.
    function get(key) {

        return (cache[key]);

    }

    // I check to see if the given key has a cached value.
    function has( key ) {

        return( key in cache );

    }


    // I remove the given key (and associated value) from the cache.
    // --
    // NOTE: Returns [this] for method chaining.
    function remove( key ) {

        delete( cache[ key ] );

        return( publ );

    }


    // I cache the given value at the given key.
    // --
    // NOTE: Returns [this] for method chaining.
    function set( key, value ) {

        cache[ key ] = value;

        return( publ );

    }

    // I initialize the cache with some dummy values
    // --
    // NOTE: Returns [this] for method chaining.
    function init() {
        this
          .initSome()
          .initMore();
        return ( publ );
    }

    // ---
    // PRIVATE METHODS
    // ---

    // I initialize the cache with some dummy values
    // --
    // NOTE: Returns [this] for method chaining.
    // NOTE: Private
    function initSome() {
        this
          .set('a', 'Alice')
          .set('b', 'Bob')
          .set('c', 'Carol');
        return ( this );
    }

    // I initialize the cache with some more dummy values
    // --
    // NOTE: Returns [this] for method chaining.
    // NOTE: Private
    function initMore() {
        return this
          .set('x', 'foo')
          .set('y', 'bar')
          .set('z', 'baz');
        return ( this );
    }

}
              
            
!
999px

Console