“Класс в JavaScript” Ответ

Класс в JavaScript

class Students {
    name;
    address;
    schoolName = "Morning Sun School";
    constructor(name,address,fatherName){
        this.name = name;
        this.address = address;
        this.fatherName = fatherName;
    }
}
const olivia = new Students("Olivia", "USA","James");
const emma = new Students("Emma", "UK", "alex");
console.log(olivia);
console.log(emma);

// Output of Olivia
Students {
    name: 'Olivia',
    address: 'USA',
    schoolName: 'Morning Sun School',
    fatherName: 'James'
  }
// Output of Emma
  Students {
    name: 'Emma',
    address: 'UK',
    schoolName: 'Morning Sun School',
    fatherName: 'alex'
  }
Ariful Islam Adil(Code Lover)

Класс в JavaScript


class Students {
    name;
    address;
    schoolName = "Morning Sun School";
    constructor(name,address,fatherName){
        this.name = name;
        this.address = address;
        this.fatherName = fatherName;
    }
    raceCompetition(){
        console.log(this.name, "start to run")
    }
}
const olivia = new Students("Olivia", "USA","James");
const emma = new Students("Emma", "UK", "alex");

console.log(olivia);
olivia.raceCompetition()

console.log(emma);
emma.raceCompetition()

// output of olivia
Students {
  name: 'Olivia',
  address: 'USA',
  schoolName: 'Morning Sun School',
  fatherName: 'James'
}
Olivia start to run

// output of Emma
Students {
  name: 'Emma',
  address: 'UK',
  schoolName: 'Morning Sun School',
  fatherName: 'alex'
}
Emma start to run
Ariful Islam Adil(Code Lover)

Класс в JavaScript


class Students {
    name;
    address;
    schoolName = "Morning Sun School";
    constructor(name,address,fatherName){
        this.name = name;
        this.address = address;
        this.fatherName = fatherName;
    }
    raceCompetition(){
        console.log(this.name, "start to run")
    }
}
const olivia = new Students("Olivia", "USA","James");
const emma = new Students("Emma", "UK", "alex");

console.log(olivia);
olivia.raceCompetition()

console.log(emma);
emma.raceCompetition()

// output of olivia
Students {
  name: 'Olivia',
  address: 'USA',
  schoolName: 'Morning Sun School',
  fatherName: 'James'
}
Olivia start to run

// output of Emma
Students {
  name: 'Emma',
  address: 'UK',
  schoolName: 'Morning Sun School',
  fatherName: 'alex'
}
Emma start to run
Ariful Islam Adil(Code Lover)

Класс в JavaScript

/*
A class is a function of a factory that will be used to create many objects,
but no code will be duplicated in creating each object. In other words, 
the code will be written only once, using that code we can create a lot of 
objects again and again.
*/

//Class
class Person{
    constructor(){
        this.name = 'Bill Gates';
    }
}
var person1 = new Person();
console.log(person1.name); //Bill Gates
Tiny Coders

Класс в JavaScript

class Support {
    name;
    designation;
    address;
    constructor(name, designation, address) {
        this.name = name;
        this.designation = designation;
        this.address = address;
    }
    startSession() {
        console.log("start a support session");
    }
}

const abraham = new Support("Abraham", "Web developer", "US");
console.log(abraham);
//output:
/* Support {
    name: 'Abraham',
    designation: 'Web developer',
    address: 'US'
  } */
Ariful Islam Adil(Code Lover)

Класс в JavaScript

//class in es6 are just functional constructor.
class PersonES6{
  constructor(firstname,lastname,age){
    this.firstname= firstname;
    this.lastname=lastname;
    this.age=age
  }
  aboutPerson(){
  console.log(`My name is ${this.firstname} ${this.lastname} and I am ${this.age} years old`)
  }
}

const shirshakES6= new Person('Shirshak','Kandel',25)
shirshakES6.aboutPerson();
Sab Tech

Класс в JavaScript


class Students {
    name;
    address;
    schoolName = "Morning Sun School";
    constructor(name,address,fatherName){
        this.name = name;
        this.address = address;
        this.fatherName = fatherName;
    }
    raceCompetition(){
        console.log(this.name, "start to run")
    }
}
const olivia = new Students("Olivia", "USA","James");
const emma = new Students("Emma", "UK", "alex");

console.log(olivia);
olivia.raceCompetition()

console.log(emma);
emma.raceCompetition()

// output of olivia
Students {
  name: 'Olivia',
  address: 'USA',
  schoolName: 'Morning Sun School',
  fatherName: 'James'
}
Olivia start to run

// output of Emma
Students {
  name: 'Emma',
  address: 'UK',
  schoolName: 'Morning Sun School',
  fatherName: 'alex'
}
Emma start to run
Ariful Islam Adil(Code Lover)

Класс в JavaScript


class Students {
    name;
    address;
    schoolName = "Morning Sun School";
    constructor(name,address,fatherName){
        this.name = name;
        this.address = address;
        this.fatherName = fatherName;
    }
    raceCompetition(){
        console.log(this.name, "start to run")
    }
}
const olivia = new Students("Olivia", "USA","James");
const emma = new Students("Emma", "UK", "alex");

console.log(olivia);
olivia.raceCompetition()

console.log(emma);
emma.raceCompetition()

// output of olivia
Students {
  name: 'Olivia',
  address: 'USA',
  schoolName: 'Morning Sun School',
  fatherName: 'James'
}
Olivia start to run

// output of Emma
Students {
  name: 'Emma',
  address: 'UK',
  schoolName: 'Morning Sun School',
  fatherName: 'alex'
}
Emma start to run
Ariful Islam Adil(Code Lover)

Класс в JavaScript


class Students {
    name;
    address;
    schoolName = "Morning Sun School";
    constructor(name,address,fatherName){
        this.name = name;
        this.address = address;
        this.fatherName = fatherName;
    }
    raceCompetition(){
        console.log(this.name, "start to run")
    }
}
const olivia = new Students("Olivia", "USA","James");
const emma = new Students("Emma", "UK", "alex");

console.log(olivia);
olivia.raceCompetition()

console.log(emma);
emma.raceCompetition()

// output of olivia
Students {
  name: 'Olivia',
  address: 'USA',
  schoolName: 'Morning Sun School',
  fatherName: 'James'
}
Olivia start to run

// output of Emma
Students {
  name: 'Emma',
  address: 'UK',
  schoolName: 'Morning Sun School',
  fatherName: 'alex'
}
Emma start to run
Ariful Islam Adil(Code Lover)

Класс в JavaScript

class Students {
    name;
    address;
    schoolName = "Morning Sun School";
    constructor(name,address,fatherName){
        this.name = name;
        this.address = address;
        this.fatherName = fatherName;
    }
}
const olivia = new Students("Olivia", "USA","James");
const emma = new Students("Emma", "UK", "alex");
console.log(olivia);
console.log(emma);

// Output of Olivia
Students {
    name: 'Olivia',
    address: 'USA',
    schoolName: 'Morning Sun School',
    fatherName: 'James'
  }
// Output of Emma
  Students {
    name: 'Emma',
    address: 'UK',
    schoolName: 'Morning Sun School',
    fatherName: 'alex'
  }
Ariful Islam Adil(Code Lover)

Ответы похожие на “Класс в JavaScript”

Вопросы похожие на “Класс в JavaScript”

Больше похожих ответов на “Класс в JavaScript” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования