Skip to main content Accessibility Feedback

Objects

Object Function Shorthand

Instead of creating a key name and then writing function () {}, you can add a named function without the function keyword.

let wizard = {

	// The old way of adding functions
	summon: function () {
		console.log('From out of thin air, watch me make a bear');
	},

	// The ES6 shorthand way
	vanish () {
		console.log(`Now you see me, now you don't.`);
	}

};

Preorder my new course on Web Components! Want to learn how to build Web Components from scratch, master best practices, and more? Preorder today and get $100 off of the launch price.


Find this useful? You can support my work by purchasing an annual membership.