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

es6 class example

var Polygon = class { 
   constructor(height, width) { 
      this.height = height; 
      this.width = width; 
   } 
}
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

PREVIOUS NEXT
Code Example
Javascript :: mui animation 
Javascript :: Graph pie 
Javascript :: javascript pass this to callback 
Javascript :: array unshift 
Javascript :: how to get data from multiple tables mongoose 
Javascript :: sweet alert 2 
Javascript :: React useEffect() the side-effect runs after every rendering 
Javascript :: http_proxy 
Javascript :: javascript strings 
Javascript :: what is promise in javascript 
Javascript :: how to create object dynamically in javascript 
Javascript :: Material-ui account icon 
Javascript :: add new field using update in mongoose 
Javascript :: adding cors in angular 
Javascript :: remix js 
Javascript :: how to sort string alphabetically in javascript 
Javascript :: array of objects in js 
Javascript :: define function js 
Javascript :: drag n drop file upload react 
Javascript :: passport local 
Javascript :: array.from 
Javascript :: typedjs 
Javascript :: proptypes for a react component 
Javascript :: use ref in component reactjs 
Javascript :: Drop it 
Javascript :: remove unused javascript angular 
Javascript :: Differences between detach(), hide() and remove() - jQuery 
Javascript :: angular ngbtooltip z-index 
Javascript :: eachfeature leaflet 
Javascript :: excluding a attribute from json strigify 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =