JavaScript Essential Training

LinkedIn Learning : Morten Rand-Hendriksen

Code Samples

Object Constructor Function

This is the code for creating an object using the a simple object declaration.

	/**
	 * Create a Backpack object.
	 */

	const backpack = {
	  name: "Everyday Backpack",
	  volume: 30,
	  color: "grey",
	  pocketNum: 15,
	  strapLength: {
		left: 26,
		right: 26,
	  },
	  lidOpen: false,
	  toggleLid: function (lidStatus) {
		this.lidOpen = lidStatus;
	  },
	  newStrapLength: function (lengthLeft, lengthRight) {
		this.strapLength.left = lengthLeft;
		this.strapLength.right = lengthRight;
	  },
	};