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

              
                <p>Open developer console to see output</p>
              
            
!

CSS

              
                
              
            
!

JS

              
                class Animal {
  constructor(noise) {
    this.noise = noise;
  }

  eat() {
    console.log("Om nom nom");
  }

  sleep() {
    console.log("Zzzzzzz");
  }

  makeNoise() {
    console.log(this.noise);
  }
}

class Pig extends Animal {
  constructor() {
    super("Oink!");
  }

  wallowInMud() {
    console.log("Aaaahh...");
  }
}

class Horse extends Animal {
  constructor() {
    super("Neigh!");
  }

  prance() {
    console.log("Eeek!!");
  }
}

class Human extends Animal {
  constructor() {
    super("Cogito ergo sum.");
  }

  inventFire() {
    console.log("Ow, that's hot!");
  }
}

class Bird extends Animal {
  constructor(noise, canFly = true) {
    super(noise);
    this.canFly = canFly;
  }

  fly() {
    if (this.canFly) {
      console.log("I'm flyyyying");
    } else {
      console.log("I can't fly, you fools!");
    }
  }

  layEgg() {
    console.log("*Plop*");
  }
}

class Owl extends Bird {
  constructor() {
    super("Hoot");
  }
}

class Kiwi extends Bird {
  constructor() {
    super("Shriek!", false);
  }
}


const HumanMixin = {
  inventFire() {
    console.log("Ow, that's hot!");
  }
};

const HorseMixin = {
  prance() {
    console.log("Eeek!!");
  }
};

class Centaur extends Animal {
  constructor() {
    super("All hail Aslan!");
  }
}
Object.assign(Centaur.prototype, HumanMixin, HorseMixin);

function createCentaur() {
  const centaur = Object.create(Animal.prototype);
  Object.assign(centaur, HumanMixin, HorseMixin);
  centaur.noise = "All hail Aslan!";
  return centaur;
}

const centaur = new Centaur();
const centaur2 = new Animal("All hail Aslan!");
Object.assign(centaur2, HumanMixin, HorseMixin);
const centaur3 = createCentaur();
console.log(centaur, centaur2, centaur3);


console.log(centaur.prance === centaur2.prance, centaur2.inventFire === centaur3.inventFire);


function createHumanMixin(cls) {
  return class HumanMixin extends cls {
    inventFire() {
      console.log("Ow, that's hot!");
    }
  };
}

function createHorseMixin(cls) {
  return class HorseMixin extends cls {
    prance() {
      console.log("Eeek!!");
    }
  };
}

class Centaur4 extends createHumanMixin(createHorseMixin(Animal)) {
  constructor() {
    super("All hail Aslan!");
  }
}

const centaur4 = new Centaur4();
console.log(centaur4);
              
            
!
999px

Console