Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

super in javascirpt

class Rectangle {
  constructor(height, width) {
    this.name = 'Rectangle';
    this.height = height;
    this.width = width;
  }
  sayName() {
    console.log('Hi, I am a ', this.name + '.');
  }
  get area() {
    return this.height * this.width;
  }
  set area(value) {
    this._area = value;
  }
}

class Square extends Rectangle {
  constructor(length) {
    this.height; // ReferenceError, super needs to be called first!

    // Here, it calls the parent class's constructor with lengths
    // provided for the Rectangle's width and height
    super(length, length);

    // Note: In derived classes, super() must be called before you
    // can use 'this'. Leaving this out will cause a reference error.
    this.name = 'Square';
  }
}
Comment

javascript super

class Parent {
  constructor() {}
  method() {}
}
class Child extends Parent {
  constructor() {
    super() // Parent.constructor
    super.method() // Parent.method
  }
}
Comment

JavaScript super() keyword

// 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();
Comment

super method in 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())
Comment

Super in javascript

super([arguments]); // calls the parent constructor.
super.functionOnParent([arguments]);
Comment

super keyword in 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>
Comment

PREVIOUS NEXT
Code Example
Javascript :: generator function 
Javascript :: mongoose + populate 
Javascript :: custom hook 
Javascript :: spring boot map json to object in controller 
Javascript :: vue js qr code scanner 
Javascript :: sequelize exclude attributes 
Javascript :: Hide ReactTooltip after hover off 
Javascript :: window.focus and window.blur jquery 
Javascript :: remove shadow in jquery 
Javascript :: alert by code stackoverflow 
Javascript :: javascript modify href attr 
Javascript :: lodash omitby 
Javascript :: javascript break inner loop 
Javascript :: js addeventlistener input searcb mobile 
Javascript :: js switch 
Javascript :: get field type file js and loop 
Javascript :: javascript wait to execute function on keyup 
Javascript :: slice() in javascript 
Javascript :: koa access request body 
Javascript :: express req.body empty 
Javascript :: if javascript 
Javascript :: yarn create react app in current directory 
Javascript :: callback in js 
Javascript :: react-with-firebase-auth 
Javascript :: feet to inches 
Javascript :: nodejs sqlite create db if not exists 
Javascript :: pandas json_normalize column with json array 
Javascript :: jquery has class 
Javascript :: get row data in datatable 
Javascript :: javascript type checking 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =