Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript es6 class

class MyClass {
  constructor() {
    this.answer = 42;
  }
}

const obj = new MyClass();
obj.answer; // 42
Comment

es6 class

//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();
Comment

Classes in ES6

class Point {
    constructor(x, y) {
        this.x = x
        this.y = y
    }

    toString() {
        return '[X=' + this.x + ', Y=' + this.y + ']'
    }
}

class ColorPoint extends Point {
    static default() {
        return new ColorPoint(0, 0, 'black')
    }

    constructor(x, y, color) {
        super(x, y)
        this.color = color
    }

    toString() {
        return '[X=' + this.x + ', Y=' + this.y + ', color=' + this.color + ']'
    }
}

console.log('The first point is ' + new Point(2, 10))
console.log('The second point is ' + new ColorPoint(2, 10, 'green'))
console.log('The default color point is ' + ColorPoint.default())
Comment

class keyword es6

class Polygon {
  constructor(...sides) {
    this.sides = sides;
  }
  // Method
  *getSides() {
    for(const side of this.sides){
      yield side;
    }
  }
}

const pentagon = new Polygon(1,2,3,4,5);

console.log([...pentagon.getSides()]); // [1,2,3,4,5]
Comment

PREVIOUS NEXT
Code Example
Javascript :: solid in css 
Javascript :: fixed header on scroll vuejs 
Javascript :: create immutable object in javascript 
Javascript :: types of method in js 
Javascript :: express delete session variable 
Javascript :: checks for valid email address syntax javascript 
Javascript :: remove last word from string javascript 
Javascript :: Create a Simple Delay Using setTimeout 
Javascript :: top bar in react js 
Javascript :: change the focus to next in angular forms 
Javascript :: var y=5 
Javascript :: mongoose objectid parse 
Javascript :: nextjs use dotnenv 
Javascript :: public static void main(dsjjsdds, jdnjd, jsndjsd, isjdjsd, sjdijs, skjdks_+) __ osakd___ +++ 
Javascript :: windows 10 retiré le theme sombre explorateur 
Javascript :: #{10000000000000000000000000000000000} js 
Python :: python check if path does not exist 
Python :: python update pip3 
Python :: matplotlib install 
Python :: change django administration title 
Python :: change figure size pandas 
Python :: cv2 grayscale 
Python :: pip clear cache command 
Python :: enumerate zip python 
Python :: python check if has attribute 
Python :: python capture exception 
Python :: validation split python 
Python :: python save figure 
Python :: change specific column name pandas 
Python :: python pdf to image 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =