“klasa w JavaScript” Kod odpowiedzi

klasa w 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)

klasa w 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)

klasa w 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)

klasa w 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

klasa w 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)

klasa w 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

klasa w 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)

klasa w 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)

klasa w 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)

klasa w 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)

Odpowiedzi podobne do “klasa w JavaScript”

Pytania podobne do “klasa w JavaScript”

Więcej pokrewnych odpowiedzi na “klasa w JavaScript” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu