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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              var orig = {
	a: new Date(),
	b: NaN,
	c: new Function(),
	d: undefined,
	e: function() {},
	f: Number,
	g: false,
	h: Infinity,
	i: ['1', '2', '3'],
	j: {
		a: 1,
		b: 2,
		c: 3
	}
};

var copy = function (obj) {

	//
	// Methods
	//

	/**
	 * Create an immutable copy of an object
	 * @return {Object}
	 */
	var cloneObj = function () {

		// Create new object
		var clone = {};

		// Loop through each item in the original
		// Recursively copy it's value and add to the clone
		for (var key in obj) {
			if (obj.hasOwnProperty(key)) {
				clone[key] = copy(obj[key]);
			}
		}

		return clone;


	};

	/**
	 * Create an immutable copy of an array
	 * @return {Array}
	 */
	var cloneArr = function () {
		return obj.map(function (item) {
			return copy(item);
		});
	};


	//
	// Inits
	//

	// Get object type
	var type = Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();

	// If an object
	if (type === 'object') {
		return cloneObj();
	}

	// If an array
	if (type === 'array') {
		return cloneArr();
	}

	// Otherwise, return it as-is
	return obj;

};

// Create an immutable copy of the original object
var newObj = copy(orig);

// Update copy
newObj.i[0] = 'a';
newObj.j.a = 'a';

console.log(orig);
console.log(newObj);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console