“Herança da classe JavaScript” Respostas de código

Herança da classe JavaScript

// Class Inheritance in JavaScript
class Mammal {
	constructor(name) {
		this.name = name;
	}
	eats() {
		return `${this.name} eats Food`;
	}
}

class Dog extends Mammal {
	constructor(name, owner) {
		super(name);
		this.owner = owner;
	}
	eats() {
		return `${this.name} eats Chicken`;
	}
}

let myDog = new Dog("Spot", "John");
console.log(myDog.eats()); // Spot eats chicken
Nathan uses Linux

Herança da classe JavaScript

class Car {
  constructor(brand) {
    this.carname = brand;
  }
  present() {
    return 'I have a ' + this.carname;
  }
}

class Model extends Car {
  constructor(brand, mod) {
    super(brand);
    this.model = mod;
  }
  show() {
    return this.present() + ', it is a ' + this.model;
  }
}

let myCar = new Model("Ford", "Mustang");
document.getElementById("demo").innerHTML = myCar.show();
Clear Cottonmouth

Herança da classe JavaScript

// parent class
class Person { 
    constructor(name) {
        this.name = name;
    }

    greet() {
        console.log(`Hello ${this.name}`);
    }
}

// inheriting parent class
class Student extends Person {

}

let student1 = new Student('Jack');
student1.greet();
SAMER SAEID

herança na aula em JS

//class in es6 are just functional constructor.
//Parent class is Person and Developer class inheritant from Person class using 
//extend and super method 
class Person{
  constructor(firstname,lastname){
    this.firstname= firstname;
    this.lastname=lastname;
    
  }
  aboutPerson(){
  console.log(`My name is ${this.firstname} ${this.lastname} `)
  }
}

class Developer extends Person{
constructor(firstname,lastname,experience,projects){
 /* //super keyword is used to call the constructor
 of its parent class to access the parent's properties and methods*/
	super(firstname,lastname);
  	this.experience=experience;
  	this.projects=projects;
  
  	aboutDev(){
      console.log(`My name is ${this.firstname} and  I have ${this.experience}
	in software development`)
}
  
  const ShirshakDev= new Developer('Shirshak','Kandel',3,13)
  console.log(ShirshakDev.aboutDev())
Shirshak kandel

Respostas semelhantes a “Herança da classe JavaScript”

Perguntas semelhantes a “Herança da classe JavaScript”

Mais respostas relacionadas para “Herança da classe JavaScript” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código