Object manipulation statements | with statement

The with statement allows you to access or manipulate the properties and methods of an object easily if you want to use a large number of statements that use the object.

For example, the with statement allows you to leave off the object name and the dot operator for statements inside the with block so you only need to type the property name to access it.

function MyCustomizedComputer (CPU, RAM, SSD) {
	this.CPU = CPU;
	this.RAM = RAM;
	this.SSD = SSD;

var DanComputer = new MyCustomizedComputer ("i5", "8GB", "120GB");

with (DanComputer) {
document.write("CPU: " + CPU);
document.write("RAM: "  +RAM);
document.write("SSD: " + SSD);

Leave a Reply