1function person(fname, lname, age, eyecolor){
2 this.firstname = fname;
3 this.lastname = lname;
4 this.age = age;
5 this.eyecolor = eyecolor;
6}
7
8myFather = new person("John", "Doe", 50, "blue");
9document.write(myFather.firstname + " is " + myFather.age + " years old.");
1class ObjectLayout {
2 constructor() {
3 this.firstName = "Larry"; //property
4 }
5
6 sayHi() { // Method
7 return `Hello from ${this.firstName}`;
8 }
9}
10
11const object = new ObjectLayout();
12// object.firstName is Larry;
13// object.sayHi() gives "Hello from Larry"
1// To make an object literal:
2const dog = {
3 name: "Rusty",
4 breed: "unknown",
5 isAlive: false,
6 age: 7
7}
8// All keys will be turned into strings!
9
10// To retrieve a value:
11dog.age; //7
12dog["age"]; //7
13
14//updating values
15dog.breed = "mutt";
16dog["age"] = 8;