1person = {
2 'name':'john smith'
3 'age':41
4};
5
6console.log(person);
7//this will return [object Object]
8//use
9console.log(JSON.stringify(person));
10//instead
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"
1function Dog() {
2 this.name = "Bailey";
3 this.colour = "Golden";
4 this.breed = "Golden Retriever";
5 this.age = 8;
6}
1//object constructor with a method
2
3function person(name,age){
4 this.name=name;
5 this.age=age;
6 this.setName= function(name){
7 this.mame=name;
8 }
9 }
10
11 const p1 = new person();
12 p1.setName("John");