Answers for "javascript object.create"

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
0

javascript object example

const car = {type:"Fiat", model:"500", color:"white"};
Posted by: Guest on September-27-2021
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
0

js objects

// To make an object literal:
const dog = {
    name: "Rusty",
    breed: "unknown",
    isAlive: false,
    age: 7
}
// All keys will be turned into strings!

// To retrieve a value:
dog.age; //7
dog["age"]; //7

//updating values
dog.breed = "mutt";
dog["age"] = 8;
Posted by: Guest on January-05-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language