cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              /**
 * Merge the contents of two or more objects together into the first object.
 * 
 * @param  {Object} target
 * @param  {Object} source1
 * @param  {Object} sourceN
 *
 * @example
 * 	extend(Person.prototype, speaker); // single source
 * 	extend(Person.prototype, mover, speaker); // multiple sources
 * 
 * @return {Object} the merged object
 */
var extend = function(target) {
		    if (!arguments[1]) return target;

	    for (var i = 1, l = arguments.length; i < l; i++) {
		        var source = arguments[i];

		        for (var prop in source) {
			            if (!source.hasOwnProperty(prop)) continue;

						            target[prop] = source[prop];
			        		}
				    }

				    	return target;
};


/**
 * Classes
 */
var Person = function(name) {
					    this.name = name;
};

var Dog = function(name) {
					    this.name = name
};


/**
 * Mixins
 */
var mover = {
					    walk: function() {
						    				    console.log(this.name + " is walking.");
					    },
					    run: function() {
						    				    console.log(this.name + " is running.");
					    }
};

var speaker = {
					    speak: function() {
						    				    console.log(this.name + " is speaking.");
					    }
};


/**
 * Merge the mixins into the classes
 */
extend(Person.prototype, mover, speaker);
extend(Dog.prototype, mover, speaker);


/**
 * Initialize the classes
 */
var adir = new Person("adir");
adir.walk();
adir.speak();

var black = new Dog("black");
black.run();
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console