Answers for "create new object from existing object javascript"

0

javascript construct new object

person = new Object();
Posted by: Guest on December-19-2020
0

create new object from existing object javascript

// With ES6 CLASSES
class User {
   constructor(firstName, lastName, dateOfBirth) {
      this.firstName = firstName;
      this.lastName = lastName;
      this.dateOfBirth = dateOfBirth;

      this.getName = function(){
          return "User's name: " + this.firstName + " " + this.lastName;
      }
   }
}

var user001 = new User("John", "Smith", 1985);

// With Object.create()
var user001 = {
   firstName: "John",
   lastName: "Smith",
   dateOfBirth: 1985,
   getName: function(){
      return "User's name: " + this.firstName + " " + this.lastName;
   }
};

var user002 = Object.create(user001);
    
user002.firstName = "Jane";
user002.lastName = "King";
user002.dateOfBirth = 1989;
Posted by: Guest on January-05-2021
0

create nodejs new object

function Person(fname, lname) {
  this.firstName = fname;
  this.lastName = lname;
}
Posted by: Guest on November-28-2020

Code answers related to "create new object from existing object javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language