“Kata kunci super di JavaScript” Kode Jawaban

Java Superscript Numbers

// Java Superscript Numbers
//	Base	Char	Code
	0		⁰		\u2070
	1		¹		\u00B9
	2		²		\u00B2
	3		³		\u00B3
	4		⁴		\u2074
    5		⁵		\u2075
    6		⁶		\u2076
    7		⁷		\u2077
    8		⁸		\u2078
    9		⁹		\u2079
Embarrassed Earthworm

Metode panggilan kelas diperpanjang dari Super di JavaScript

// this is how we call method from a super class(i.e MAIN CLASS) to extended class
class Person {
 constructor(name, age) {
  this.name = name;
  this.age = age;
 }
greet() {
  console.log(`Hi, all my name is ${this.name}`);
 }
}

class Employee extends Person {
 constructor(name, age, employer) {
  super(name, age);  // NOTE : super must call before accessing (this)
  this.employer = employer;
 }

 greeting() {
  super.greet();  // this is how we call
  console.log(`I'm working at ${this.employer}`);
 }
}

let Steve = new Employee('Xman', 25 , 'Skynet');
Steve;
Steve.greeting(); // check by consoling MATE
Outlander

Kata kunci super di JavaScript

<!DOCTYPE html>
<html>
    <head> </head>
    <body>
        <script>
            class Person {
                constructor(name, age) {
                    this.name = name;
                    this.age = age;
                }
                atWork() {
                    return this.name + " is at work, ";
                }
                atHome() {
                    return this.name + " is at home";
                }
                sleeping() {
                    return this.name + " is sleeping";
                }
            }
            class FashionDesigner extends Person {
                constructor(name, age) {
                    super(name, age);
                }
                profession() {
                    return this.name +
                      " is a Fashion Designer";
                }
                doTasks() {
                    return super.atWork() + this.profession();
                }
            }
            function display(content) {
                console.log(content);
            }
            const character =
            new FashionDesigner("Sayan", 30);
            display(character.profession());
            display(character.atHome());
            display(character.doTasks());
        </script>
    </body>
</html>
Otmane TOUHAMI

Kata kunci javascript super ()

// parent class
class Person { 
    constructor(name) {
        this.name = name;
    }
    greet() {
        console.log(`Hello ${this.name}`);
    }
}
// inheriting parent class
class Student extends Person {
    constructor(name) {
            console.log("Creating student class");
                // call the super class constructor and pass in the name parameter
        super(name);
    }
}
let student1 = new Student('Jack');
student1.greet();
SAMER SAEID

Jawaban yang mirip dengan “Kata kunci super di JavaScript”

Pertanyaan yang mirip dengan “Kata kunci super di JavaScript”

Lebih banyak jawaban terkait untuk “Kata kunci super di JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya