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
/* A class is a blue print that you create objects from*/
/* How to create a class in javascript in it's simplest form*/
class Fruit{
}
var apple =new Fruit ();
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
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
/*
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
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
//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();
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
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
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
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
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
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
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
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
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
class Person
{
constructor(name)
{
this.name = name;
console.log("HELLO WORLD")
/*console.log will show HELLO WORLD everytime an instance of Person is created*/
}
}
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
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
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
const p = new Rectangle(); // ReferenceError
class Rectangle {}
// functions can be called even before they are defined, but classes must be defined before they can be constructed.
class NameOfClass {
//class declaration first letter should be capital it's a convention
obj="text";
obj2="some other text";
}
//always call class with "new" key word
console.log(new NameOfClass);
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