create new object from existing object javascript
person = new Object();// 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;function Person(fname, lname) {
this.firstName = fname;
this.lastName = lname;
}
Also in JavaScript:
- redirect to url onPress react native
- js objects
- javascript check alpha and space only
- call node.js file electron
- javascript clear div
- create nodejs new object
- convert json string to json object in java
- how to set data attribute in js using setattribute
- .includes javascript
- js container class
- cypress memory leak
- factorial in javascript using for loop
- how to write a variable in js
- redux acions
- how to make 1st letter capital in ejs
- how to install all needed modules in node
- split string jquery
- how to conver time format to 12 hours in javascript
- append meta tag to head javascript
- optimized bubble sort javascript
- number counter html
- js vue array change position
- jquery remove keypress event
- javascript search like