“Criando classe JavaScript” Respostas de código

classe JavaScript

class ClassMates{
	constructor(name,age){
    	this.name=name;
      	this.age=age;
    }
  	displayInfo(){
    	return this.name + "is " + this.age + " years old!";
    }
}

let classmate = new ClassMates("Mike Will",15);
classmate.displayInfo();  // result: Mike Will is 15 years old!
Spotted Tailed Quoll

Classe JavaScript

class Polygon {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }

  get area() {
    return this.calcArea();
  }

  calcArea() {
    return this.height * this.width;
  }
}

const square = new Polygon(10, 10);

console.log(square.area);
Perfect Pheasant

Criando classe JavaScript

// constructor function
function Person () {
    this.name = 'John',
    this.age = 23
}

// create an object
const person1 = new Person();
SAMER SAEID

Respostas semelhantes a “Criando classe JavaScript”

Procure respostas de código populares por idioma

Procurar outros idiomas de código