node js create new object code example
Example 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
Example 2: js create new object
let bike = { name: 'SuperSport', maker:'Ducati', start: function() { console.log('Starting the engine...'); }};bike.start(); //Output: Starting the engine.../* Adding method stop() later to the object */bike.stop = function() { console.log('Applying Brake...'); }bike.stop(); //Output: Applying Brake...