Answers for "object.create in javascript"

1

create nodejs new object

const personFactory = (firstName, lastName, email) => {
    return {
        firstName: firstName,
        lastName: lastName,
        email: email,
        info() {
            return `${this.firstName} ${this.lastName}, ${this.email}`;
        }
    };
};

let person = personFactory('John', 'Doe', '[email protected]');

console.log(person.info());
Posted by: Guest on November-28-2020
1

create nodejs new object

class Person {
  constructor(fname, lname) {
    this.firstName = fname;
    this.lastName = lname;
  }
}

const person = new Person('testFirstName', 'testLastName');

console.log(person.firstName); // testFirstName
console.log(person.lastName); // testLastName
Posted by: Guest on November-28-2020
3

how to create object js

function person(fname, lname, age, eyecolor){
  this.firstname = fname;
  this.lastname = lname;
  this.age = age;
  this.eyecolor = eyecolor;
}

myFather = new person("John", "Doe", 50, "blue");
document.write(myFather.firstname + " is " + myFather.age + " years old.");
Posted by: Guest on August-11-2020
1

js object.create example

function userCreator (name, score) {
	const newUser = Object.create(userFunctionStore);
  	newUser.name = name;
  	newUser.score = score;
  	return newUser;
};

const userFunctionStore = {
  	increment: function() {
      	this.score++;
    },
  
  	login: function() {
     	console.log("Logged in!"); 
    }
};

const user1 = userCreator("Justin", 41);
const user2 = userCreator("Rainer", 5);
user1.increment();
console.log(user1.score) // 42
Posted by: Guest on April-14-2021
1

make an object javascript

class ObjectLayout {
	constructor() {
    	this.firstName = "Larry"; //property
    }
  
  	sayHi() { // Method
    	return `Hello from ${this.firstName}`;
    }
}

const object = new ObjectLayout();
// object.firstName is Larry;
// object.sayHi() gives "Hello from Larry"
Posted by: Guest on November-03-2020
1

how to make an object in javascript

let myDog = {		
  legs: value			

}
  console.log(myDog);
/*Doesn't have to be a Dog it can be anyting you want*/
Posted by: Guest on June-29-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language