Pen Settings



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


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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


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.


                <h1>Memento Example</h1>
<p>This pattern provides the ability to restore an object to its previous state. Memento is implemented with three objects: the Originator, a Caretaker and a Memento. The Originator is some object that has an internal state. This internal state can be saved in a Memento object. The Caretaker first asks the Originator for a Memento object and stores it. Then some actions are performed on the Originator. To roll back to the state before the actions, Caretaker returns the corresponding Memento object to the Originator. The Memento object itself is an opaque object (the Caretaker cannot, or should not, change it).</p>
<button id="sender1">Underline Text</button>
<button id="sender2">Strong Text</button>
<button id="sender3">Italic Text</button>
<button id="sender4">Undo</button>
<button id="reset">Reset</button>
<div id="result">
No result. Press a button above.
<div class="items" id="logs">


                body {padding:10px;}
#receiver {
  border:1px solid gray;
  padding: 5px;
div.items {
  border:1px solid #222; 
div.items div, div.items header {
  border-bottom:1px solid #000;


                // Originator
function Text(text) {
  var txt = text;
  this.getText = function() {
  return txt;
  this.underline = function() {
  txt = '<u>' + txt + '</u>';
  this.strong = function(text) {
  txt = '<b>' + txt + '</b>';
  this.italic = function(text) {
  txt = '<i>' + txt + '</i>';
  this.storeState = function(action) {
  return new Memento(txt, action);
  this.restoreState = function(memento) {
  if(!memento) return;
  setup.addRecord(memento, true);  
  txt = memento.getState();  
// Memento
function Memento(txt, action) {
  var state = txt;
  var action = action;
  this.getState = function() {
    return state;
  this.getAction = function() {
    return action;
// CareTaker
function CareTaker() {
  this.results = [];
  this.setMemento = function(memento) {
  this.getMemento = function() {
    return this.results.pop();
// Run it all
function Setup() {
   this.logCont = document.getElementById('logs');
   this.resCont = document.getElementById('result');
} = function() {

  var text = prompt('Insert some text', ''); 
  var _this = this;
  var txt = new Text(text);
  var careTaker = new CareTaker();
  var btn1 = document.getElementById("sender1");
  btn1.addEventListener("click", function() {
  careTaker.setMemento(txt.storeState('Underline text'));  
  var btn2= document.getElementById("sender2");
  btn2.addEventListener("click", function() {
  careTaker.setMemento(txt.storeState('Strong text'));  
  var btn3 = document.getElementById("sender3");
  btn3.addEventListener("click", function() {
  careTaker.setMemento(txt.storeState('Italic text'));  
  var btn4 = document.getElementById("sender4");
  btn4.addEventListener("click", function() { 
  var reset = document.getElementById("reset"); // clean table
  reset.addEventListener("click", function() {
Setup.prototype.showResult = function(res) {
  this.resCont.innerHTML = res;
Setup.prototype.removeResult = function() {
  this.resCont.innerHTML = 'No result. Press a button above.';
Setup.prototype.addRecord = function(memento, undo) { // add record 
  var record = document.createElement('div');
  var msg = '';
  if(undo) var msg = 'Undone '; 
  record.textContent = msg + memento.getAction();
Setup.prototype.removeMsg = function(elem) {
  var msgs =;
  msgs.forEach(function(element, index, array) {
   if(msgs[index].tagName != 'header'.toUpperCase()) {
var setup = new Setup();;