Answers for "how to create a constructor in javascript"

23

javascript constructor function

function ClassMates(name,age){
  this.name=name;
  this.age=age;
  this.displayInfo=function(){
    return this.name + "is " + this.age + "year's old!";
  }
}

let classmate1 = new ClassMates("Mike Will", 15);
classmate.displayInfo(); // "Mike Will is 15 year's old!"
Posted by: Guest on November-20-2019
4

constructor in javascript

class Person {
  constructor(name) {
    this.name = name;
  }
  introduce() {
    console.log(`Hello, my name is ${this.name}`);
  }
}
Posted by: Guest on June-23-2021
18

constructor in js

A constructor is a function that creates an instance of a class
  which is typically called an “object”. In JavaScript, a constructor gets 
  called when you declare an object using the new keyword.
  The purpose of a constructor is to create an object and set values if 
  there are any object properties present.
Posted by: Guest on May-22-2020
8

javascript constructor object

function Person(first, last, age, eye) {
  this.firstName = first;
  this.lastName = last;
  this.age = age;
  this.eyeColor = eye;
}
Posted by: Guest on December-01-2019
9

js constructor object

function Car(make, model, year) {
  this.make = make;
  this.model = model;
  this.year = year;
}

var car1 = new Car('Eagle', 'Talon TSi', 1993);

console.log(car1.make);
// expected output: "Eagle"
Posted by: Guest on December-03-2019
1

how to create a constructor in javascript

function Bird() {
  this.name = "Albert";
  this.color  = "blue";
  this.numLegs = 2;
}

let blueBird = new Bird();
Posted by: Guest on March-10-2021

Code answers related to "how to create a constructor in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language