1function userCreator (name, score) {
2 const newUser = Object.create(userFunctionStore);
3 newUser.name = name;
4 newUser.score = score;
5 return newUser;
6};
7
8const userFunctionStore = {
9 increment: function() {
10 this.score++;
11 },
12
13 login: function() {
14 console.log("Logged in!");
15 }
16};
17
18const user1 = userCreator("Justin", 41);
19const user2 = userCreator("Rainer", 5);
20user1.increment();
21console.log(user1.score) // 42
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"
1const person = {
2 name: 'Anthony',
3 age: 32,
4 city: 'Los Angeles',
5 occupation: 'Software Developer',
6 skills: ['React','JavaScript','HTML','CSS']
7}
8
9//Use Template Literal to also log a message to the console
10const message = `Hi, I'm ${person.name}. I am ${person.age} years old. I live in ${person.city}. I am a ${person.occupation}.`;
11console.log(message);
1function Car(make, model, year) {
2 this.make = make;
3 this.model = model;
4 this.year = year;
5}
6