“Classes JavaScript” Respostas de código

Classes JavaScript

class Car {
  constructor(name, year) {
    this.name = name;
    this.year = year;
  }

  carDetails() {
    console.log("Car name: " + this.name, "\nCar year: "+ this.year);
  }

  drive() {
    console.log("Driving!")
  }

}

let car = new Car("Audi", 2019);
car.carDetails();
car.drive();
The Cat Coder

Classes JavaScript

class Rectangle {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }
  // Getter
  get area() {
    return this.calcArea();
  }
  // Method
  calcArea() {
    return this.height * this.width;
  }
}

const square = new Rectangle(10, 10);

console.log(square.area); // 100
HimansaE

Classes JavaScript

//private but is a good example
class includes {
    constructor(){}
  
    inculde_apps(file) { 
      var script  = document.createElement('script'); 
      script.src  = "ext/apps/"+file; 
      script.type = 'text/javascript'; 
      document.getElementsByTagName('body').item(0).appendChild(script);
    } 
    
    inculde_scripts(file) { 
      var script  = document.createElement('script'); 
      script.src  = "ext/scripts/"+file; 
      script.type = 'text/javascript'; 
      document.getElementsByTagName('body').item(0).appendChild(script);
    } 
    
    inculde_css(file) { 
        var script  = document.createElement('link'); 
        script.rel  = "stylesheet"; 
        script.type = 'text/css'; 
        script.href = "css/"+file;
        document.getElementsByTagName('head').item(0).appendChild(script);
    }
  }
White Lord

Classes JavaScript

class Car {
  constructor(name, year) {
    this.name = name;
    this.year = year;
  }
}
naly moslih

Classes JavaScript

class Car {
  constructor(name, year) {
    this.name = name;
    this.year = year;
  }
}
naly moslih

Classes JavaScript

class Person {
  constructor(name) {
    this.name = name;
  }
}
SAMER SAEID

Respostas semelhantes a “Classes JavaScript”

Perguntas semelhantes a “Classes JavaScript”

Mais respostas relacionadas para “Classes JavaScript” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código